Link to home
Start Free TrialLog in
Avatar of mathiaso
mathiaso

asked on

VB script to add element in XML

I have an XML file with attributes. I want to add elements to this with VB script.

As an example I want to add this element to my example XML file.
<category name="OP\Monofilter\100\Median">
<setting name="radius" type="string" value="1" />

Open in new window

Example XML
<?xml version="1.0"?>
<OPsettings version="1.0">
 ...
  <category name="OP\ListMonofilter">
    <setting name="1" type="string" value="Pan" />
  </category>
  <category name="OP\Monofilter\1\Histogram">
    <setting name="Monomatic" type="boolean" value="1" />
    <setting name="low" type="string" value="0.001" />
    <setting name="high" type="string" value="1" />
    <setting name="gamma" type="string" value="1" />
  </category>
</OPSettings> 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mathiaso
mathiaso

ASKER

Thanks for your explanation. Is there a way to get line breaks before "<setting name..." this would make the XML easier to read
In vbscript you can insert the CR and LF characters to a string like follows:

xml2.loadXML "<category name=""OP\Monofilter\100\Median"">" & vbCrLf & "<setting name=""radius"" type=""string"" value=""1000"" />" & vbCrLf & "</category>"

Open in new window