lib/ruby_nsx_cli/nsx_objects/nsxobject.rb
def inject_xml(xml, grandparent, parent, node)
      doc = Nokogiri::XML(xml)
      parent_xml = doc.at_css(parent)
      if parent_xml.nil?
        grandparent_xml = doc.at_css(grandparent)
        raise "No valid parent to insert XML block into with nodes provided: #{parent_xml}, #{grandparent_xml}" if grandparent_xml.nil?
        parent_xml = Nokogiri::XML::Node.new(parent, doc)
        grandparent_xml << parent_xml
      end
      parent_xml << node
      return doc
    end
# Inserts an XML block into the provided XML at the parent node
# If the parent node does not exist, then the parent node will be created
# with the node injected into the grandparent node
# Returns the updated xml with the node injected
#
# @param xml [String] the NSX endpoint to send the request
# @param grandparent [String] the grandparent attribute of the node to insert;
# only required if the parent node is not included in the provided xml string
# @param parent [String] the parent attribute of the node to insert
# @param node [String] the payload to send to `:api_endpoint`
# @return [String] the original XML string including the inserted node.
Inserts an XML block into the provided XML at the parent node
If the parent node does not exist, then the parent node will be created
with the node injected into the grandparent node
Returns the updated xml with the node injected
Inserts an XML block into the provided XML at the parent node If the parent node does not exist then the parent node will be created with the node injected into the grandparent node Returns the updated xml with the node injected
def inject_xml(xml, grandparent, parent, node)
      doc = Nokogiri::XML(xml)
      parent_xml = doc.at_css(parent)
      if parent_xml.nil?
        grandparent_xml = doc.at_css(grandparent)
        raise "No valid parent to insert XML block into with nodes provided: #{parent_xml}, #{grandparent_xml}" if grandparent_xml.nil?
        parent_xml = Nokogiri::XML::Node.new(parent, doc)
        grandparent_xml << parent_xml
      end
      parent_xml << node
      return doc
    end
def inject_xml ( xml , grandparent , parent , node ) doc = Nokogiri :: XML ( xml ) parent_xml = doc . at_css ( parent ) if parent_xml . nil? grandparent_xml = doc . at_css ( grandparent ) raise "No valid parent to insert XML block into with nodes provided: #{parent_xml}, #{grandparent_xml}" if grandparent_xml . nil? parent_xml = Nokogiri :: XML :: Node . new ( parent , doc ) grandparent_xml << parent_xml end parent_xml << node return doc end
Inserts an XML block into the provided XML at the parent node
If the parent node does not exist, then the parent node will be created
with the node injected into the grandparent node
Returns the updated xml with the node injected
Inserts an XML block into the provided XML at the parent node If the parent node does not exist then the parent node will be created with the node injected into the grandparent node Returns the updated xml with the node injected
the original XML string including the inserted node.
the original XML string including the inserted node .
String
xml
the NSX endpoint to send the request
the NSX endpoint to send the request
grandparent
the grandparent attribute of the node to insert; only required if the parent node is not included in the provided xml string
the grandparent attribute of the node to insert ; only required if the parent node is not included in the provided xml string
parent
the parent attribute of the node to insert
the parent attribute of the node to insert
node
the payload to send to `:api_endpoint`
the payload to send to ` : api_endpoint `