Murali
asked on
read XML file VB script
Hi, I have xml file something like this
<shop>
<fruit="apple" cost="20" />
<fruit="orange" cost="30" />
<fruit="mango" cost="50" />
<vegetable="tamoto" cost="10" />
<vegetable="potato" cost="15" />
<fruit="curly flower" cost="60" />
</shop>
How do I execte the following operation in vbscript
read all furits and vegetable
Modify the name and cost
delete any line
add some more line
Thanks
<shop>
<fruit="apple" cost="20" />
<fruit="orange" cost="30" />
<fruit="mango" cost="50" />
<vegetable="tamoto" cost="10" />
<vegetable="potato" cost="15" />
<fruit="curly flower" cost="60" />
</shop>
How do I execte the following operation in vbscript
read all furits and vegetable
Modify the name and cost
delete any line
add some more line
Thanks
ASKER
need vbs file... dont have vb6
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi ZC2, thanks for your assitance.. am going throught script the checking.. will update you soon...
ASKER
Hi ZC2, it shows error
Object required: 'documentElement'
Object required: 'documentElement'
ASKER
I have changed the input xml file and xml version is 1, encoding UTF 8
ASKER
I have modifed the script variables to another xml file... That XML file has a dtd file defined in it...
When I run the vbs script file it is showing error DTD phibited and documentElement not found...
If I remove the the line which load the DTD file then the script works fine..
Could you please assist.
When I run the vbs script file it is showing error DTD phibited and documentElement not found...
If I remove the the line which load the DTD file then the script works fine..
Could you please assist.
you could try to add the following lines after the line 4.
xml.validateonparse=false
xml.setProperty "ProhibitDTD", false
In my example the line 9 prints out the error but actually does not terminate the script. Please modify the script the way you want so it will correctly terminated or do anything you need when an error occurs.
xml.validateonparse=false
xml.setProperty "ProhibitDTD", false
In my example the line 9 prints out the error but actually does not terminate the script. Please modify the script the way you want so it will correctly terminated or do anything you need when an error occurs.
ASKER
Hi ZC2, thanks that worked.. now trying to delete the line.. I tried the example written here exactly... tried to delete the mango...
The scripts executes with no error but nothing happens.. I still can see the mango in xml file.. does not deletes...
I save the above correct xml to shop.xml file... and this what I used....
Option Explicit
Dim xml
set xml = CreateObject("Msxml2.DOMDo cument.6.0 ")
xml.async = False
xml.validateonparse=false
xml.setProperty "ProhibitDTD", false
' 1. read the XML
xml.load("shop.xml")
if xml.parseError.errorCode <> 0 then
WScript.Echo "Error: " & xml.parseError.errorCode & " Reason: " & xml.parseError.reason
end if
call xml.setProperty("Selection Language", "XPath")
' 4. Delete "mango"
dim e, nm
nm = "mango"
set e = xml.documentElement.select SingleNode ("/shop/*[ @name='" & nm & "']")
if not e is Nothing then e.parentNode.removeChild( e )
The scripts executes with no error but nothing happens.. I still can see the mango in xml file.. does not deletes...
I save the above correct xml to shop.xml file... and this what I used....
Option Explicit
Dim xml
set xml = CreateObject("Msxml2.DOMDo
xml.async = False
xml.validateonparse=false
xml.setProperty "ProhibitDTD", false
' 1. read the XML
xml.load("shop.xml")
if xml.parseError.errorCode <> 0 then
WScript.Echo "Error: " & xml.parseError.errorCode & " Reason: " & xml.parseError.reason
end if
call xml.setProperty("Selection
' 4. Delete "mango"
dim e, nm
nm = "mango"
set e = xml.documentElement.select
if not e is Nothing then e.parentNode.removeChild( e )
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it is showing some msg
msxml6.dll: Expected token 'EOF' found '*'.
selected node /shop/... and displaying the nm value i have defined...
msxml6.dll: Expected token 'EOF' found '*'.
selected node /shop/... and displaying the nm value i have defined...
ASKER
for adding new line working perfect :)
I ran your shorten version of the script, it deletes the mango node seamlessly.
Sorry, for a dull question, do you realize you need to print out or save the xml file? The script does not modify the original shop.xml, it works with the node tree in the memory.
Sorry, for a dull question, do you realize you need to print out or save the xml file? The script does not modify the original shop.xml, it works with the node tree in the memory.
ASKER
ZC2, EE does not allowed me to give more than 500!!! otherwise anything for you.. Loved it.. thank alot
you're welcome
ASKER
Hi AZ2, in few servers it is showing following error.
activex component can't create object: 'Msxml2.domdocument.6.0'
activex component can't create object: 'Msxml2.domdocument.6.0'
Please make sure the MSXML v6 is installed, or try to change the PROGID string from "Msxml2.DOMDocument.6.0" to "Msxml2.DOMDocument"
3.zip