2

I am stuck in parsing the below XML.

<?xml version="1.0" encoding="UTF-8"?>
<Provisioning xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Request>
    <Header>
      <Command>Create</Command>
      <EntityIdentifiers>
        <Identifier Type="CosName" Value="Super_Super"/>
      </EntityIdentifiers>
      <EntityName>COS</EntityName>
    </Header>
    <Data>
      <COS>
        <ServiceLevels>
          <ServiceLevel>
            <ServiceName>MMS</ServiceName>
            <ServiceLevelName>Super user</ServiceLevelName>
          </ServiceLevel>
          <ServiceLevel>
            <ServiceName>General</ServiceName>
            <ServiceLevelName>Super user</ServiceLevelName>
          </ServiceLevel>
          <ServiceLevel>
            <ServiceName>MMBOX</ServiceName>
            <ServiceLevelName>Super user</ServiceLevelName>
          </ServiceLevel>
        </ServiceLevels>
        <CosName>Super_Super</CosName>
      </COS>
    </Data>
  </Request>
</Provisioning>

I need to replace the "Identifier" tags "Type" and "Value" to other respective values. And also change all values of nodes under "ServiceLevel".

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "false"
xmlDoc.Load("C:\1.xml")
Set nodeXML = xmlDoc.getElementsByTagName("Identifier")
Set node = nodeXML.item(0)
MsgBox node.Text
2

1 Answer 1

3

Microsoft.XMLDOM is outdated and shouldn't be used anymore. Use Msxml2.DOMDocument instead.

Set xml = CreateObject("Msxml2.DOMDocument")

Select a single node with an XPath expression like this:

Set node = xml.SelectSingleNode("//node_name")

and several nodes with the same name like this:

Set nodes = xml.SelectNodes("//node_name")

Attributes of a node (<node attribute="value">) can be changed like this:

node.SetAttribute("attribute_name") = "new value"

and node text (<node>text</node>) like this:

node.Text = "new text"

Beware that the names of XML nodes and attributes are case-sensitive.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.