Reputation: 105
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
Upvotes: 2
Views: 2141
Reputation: 200573
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.
Upvotes: 3