ProgrammingBrain Posted March 12, 2011 Share Posted March 12, 2011 i want to Edit an XML file using _XMLDOMWrapper.au3 UDF but i cant there is some thing wrong , i want to edit an value in specified root section in an XML file has many roots sections for example :want to change value1 data in root1 section to "Data_False" help XML File <?xml version="1.0" encoding="UTF8"?> <root1> <value1>data1</value1> <value2>data2</value2> <value3>data3</value3> <value4>data4</value4> </root1> <root2> <value1>data1</value1> <value2>data2</value2> </root2> Code #include <_XMLDOMWrapper.au3> #include <Array.au3> $sXmlFile = @ScriptDir & "\XML_file.xml" $sXPath = "/root1/value1" _XMLFileOpen($sXmlFile) For $n = 1 To 4 $aRET = _XMLGetValue($sXPath) _ArrayDisplay($aRET, "Before") $sNewVal = String($aRET[1] = "Data_False") _XMLUpdateField($sXPath, $sNewVal) $aRET = _XMLGetValue($sXPath) _ArrayDisplay($aRET, "After") Next Link to comment Share on other sites More sharing options...
Bowmore Posted March 12, 2011 Share Posted March 12, 2011 An XML document is only allowed to have 1 root node. You could try modifying the file be adding a proper root element. <?xml version="1.0" encoding="UTF8"?> <realRoot> <root1> <value1>data1</value1> <value2>data2</value2> <value3>data3</value3> <value4>data4</value4> </root1> <root2> <value1>data1</value1> <value2>data2</value2> </root2> </realRoot> "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
ProgrammingBrain Posted March 12, 2011 Author Share Posted March 12, 2011 An XML document is only allowed to have 1 root node.You could try modifying the file be adding a proper root element.<?xml version="1.0" encoding="UTF8"?> <realRoot> <root1> <value1>data1</value1> <value2>data2</value2> <value3>data3</value3> <value4>data4</value4> </root1> <root2> <value1>data1</value1> <value2>data2</value2> </root2> </realRoot>but i saw some xml files like this<?xml version="1.0" encoding="UTF8"?> <root1> <value1>data1</value1> <value2>data2</value2> <value3>data3</value3> <value4>data4</value4> </root1> <root2> <value1>data1</value1> <value2>data2</value2> </root2> Link to comment Share on other sites More sharing options...
ChrisL Posted March 12, 2011 Share Posted March 12, 2011 but i saw some xml files like this<?xml version="1.0" encoding="UTF8"?> <root1> <value1>data1</value1> <value2>data2</value2> <value3>data3</value3> <value4>data4</value4> </root1> <root2> <value1>data1</value1> <value2>data2</value2> </root2>Really?Can Internet Explorer open the XML file? [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ProgrammingBrain Posted March 13, 2011 Author Share Posted March 13, 2011 Really?Can Internet Explorer open the XML file?no internet explorer cant open it but this xml model for an program config.xmland this program can write data in root1 and root2 with out any problem ? Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 13, 2011 Share Posted March 13, 2011 The _XMLDOMWrapper UDF uses the MSXML API. It doesn't have any magic in it that allows it to use badly formatted XML. What program is it that uses this bad XML for a config file? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
ChrisL Posted March 13, 2011 Share Posted March 13, 2011 (edited) Your going to need to use some sort of bodge like this... #include "_XMLDomWrapper.au3" #Include <String.au3> $XMLString = _ReturnXMLDataAsString("test.xml","root1") _XMLLoadXML($XMLString) $data = _XMLGetFirstValue("/root1/value1") Msgbox(0,"",$data) Func _ReturnXMLDataAsString($file,$root) Local $Str = FileRead($file) Local $aXMLData = _StringBetween($Str,$root,$root) Local $XML = "<" & $root & $aXMLData[0] & $root & ">" Return $XML EndFunc Func _XMLGetFirstValue($node) Local $ret_val $ret_val = _XMLGetValue($node) If IsArray($ret_val) Then Return ($ret_val[1]) Else Return SetError(1,3,0) EndIf EndFunc Edited March 13, 2011 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ProgrammingBrain Posted March 13, 2011 Author Share Posted March 13, 2011 Fixed thanks guys for help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now