eltorro Posted January 4, 2006 Share Posted January 4, 2006 (edited) I've needed these for a while and didn't find any suitable so here's what I came up with. _XMLDomWrapper.au3 Edit: Updated Version 03.07.2008 (Version 1.0.3.87) Total downloads: Edit: MDI Version 3.2.2006I have moved most of my code to google code. and dispensed with the dynamic ip service.Download here:_XMLDomWrapper.au3SVN code is here. <div class='codetop'>CODE</div><div class='codemain' style='height:200px;overflow:auto'> _XMLCreateFile($sPath, $sRootNode, [$bOverwrite = False]) Creates an XML file with the given name and root.(Requires: #include <_XMLDomWrapper.au3>) _XMLFileOpen($sXMLFile,[$sNamespace=""],[$ver=-1]) Creates an instance of an XML file.(Requires: #include <_XMLDomWrapper.au3>) ;============================================================================== _XMLGetChildNodes ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>) _XMLGetNodeCount ( strXPath, strQry = "", iNodeType = 1 ) Get node count for specified path and type. (Requires: #include <_XMLDomWrapper.au3>) _XMLGetPath ( strXPath ) Returns a nodes full path based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>) ;============================================================================== _XMLSelectNodes ( strXPath ) Selects XML Node(s) based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>) _XMLGetField ( strXPath ) Get XML Field(s) based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>) _XMLGetValue ( strXPath ) Get XML Field based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>) _XMLGetChildText ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>) _XMLUpdateField ( strXPath, strData ) Update existing node(s) based on XPath specs.(Requires: #include <_XMLDomWrapper.au3>) _XMLReplaceChild ( objOldNode, objNewNode, ns = "" ) Replaces a node with a new node. (Requires: #include <_XMLDomWrapper.au3>) ;============================================================================== _XMLDeleteNode ( strXPath ) Delete specified XPath node.(Requires: #include <_XMLDomWrapper.au3>) _XMLDeleteAttr ( strXPath, strAttrib ) Delete attribute for specified XPath(Requires: #include <_XMLDomWrapper.au3>) _XMLDeleteAttrNode ( strXPath, strAttrib ) Delete attribute node for specified XPath(Requires: #include <_XMLDomWrapper.au3>) ;============================================================================== _XMLGetAttrib ( strXPath, strAttrib, strQuery = "" ) Get XML attribute based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>) _XMLGetAllAttrib ( strXPath, ByRef aName, ByRef aValue, strQry = "" ) Get all XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>) _XMLGetAllAttribIndex ( strXPath, ByRef aName, ByRef aValue, strQry = "", NodeIndex = 0 ) Get all XML Field(s) attributes based on Xpathn and specific index.(Requires: #include <_XMLDomWrapper.au3>) _XMLSetAttrib ( strXPath, strAttrib, strValue = "" ) Set XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>) ;============================================================================== _XMLCreateCDATA ( strNode, strCDATA, strNameSpc = "" ) Create a CDATA SECTION node directly under root. (Requires: #include <_XMLDomWrapper.au3>) _XMLCreateComment ( strNode, strComment ) Create a COMMENT node at specified path.(Requires: #include <_XMLDomWrapper.au3>) _XMLCreateAttrib ( strXPath,strAttrName,strAttrValue="" ) Creates an attribute for the specified node. (Requires: #include <_XMLDomWrapper.au3>) ;============================================================================== _XMLCreateRootChild ( strNode, strData = "", strNameSpc = "" ) Create node directly under root.(Requires: #include <_XMLDomWrapper.au3>) _XMLCreateRootNodeWAttr ( strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under root node with attributes.(Requires: #include <_XMLDomWrapper.au3>) _XMLCreateChildNode ( strXPath, strNode, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node.(Requires: #include <_XMLDomWrapper.au3>) _XMLCreateChildWAttr ( strXPath, strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node with Attributes. (Requires: #include <_XMLDomWrapper.au3>) ;============================================================================== _XMLSchemaValidate ( sXMLFile, ns, sXSDFile ) _XMLSchemaValidate($sXMLFile, $ns, $sXSDFile) Validate a document against a DTD. (Requires: #include <_XMLDomWrapper.au3>) _XMLGetDomVersion ( ) Returns the XSXML version currently in use. (Requires: #include <_XMLDomWrapper.au3>) _XMLError ( sError = "" ) Sets or Gets XML error message generated by XML functions.(Requires: #include <_XMLDomWrapper.au3>) _XMLUDFVersion ( ) eturns the UDF Version number. (Requires: #include <_XMLDomWrapper.au3>) _XMLTransform ( oXMLDoc, Style = "",szNewDoc="" ) Transfroms the document using built-in sheet or xsl file passed to function. (Requires: #include <_XMLDomWrapper.au3>) _XMLNodeExists( $strXPath) Checks for the existence of the specified path. (Requires: #include <_XMLDomWrapper.au3>)</div> Here's a sample prog to show some of its usefullness. Its the gui sample from the /Examples/gui folder. SaveSampleControls.au3 Works with newer wrapper XmlExample.au3 _XMLExample.au3 downloads: The only thing I could not get to work was getting the checkbox state in the 2nd treeview. Please give me some feedback. Steve Edit: Bug Fix: _XMLGetField not returning array count. Added Func _XMLSelectNodes($sXPath) returns a list of node namesEdit: Corrected Def for _XMLGetAllAttrib Edit: Bugfix for _XMLCreateCDATA Bugfix for _XMLGetValue returns array as supposed to.Edit: June 29,2006 Added count to index[0] of the _XMLGetValue return Change _XMLFileOpen _XMLFileCreate to look for available MSXML obj. Added optional flag to _XMLFileCreate for specifiying UTF-8Edit: March , Apr 2007 Mar 30, 2007 Rewrote _AddFormat function to break up tags( no indentation) Added _XMLTransform() which runs the document against a xsl(t) style sheet for indentation. Changed _XMLCreateRootChildWAttr() to use new formatting Changed _XMLChreateChildNode() to use new formatting Apr 02, 2007 Added _XMLReplaceChild() Apr 03, 2007 Changed other node creating function to use new formatting Changed _XMLFileOpen() _XMLFileCreate to take an optional version number of MSXML to use. Changed _XMLFileOpen() _XMLFileCreate find latest MSXML version logic.Edit: Apr 24, 25 2007 Fixed _XMLCreateChileNodeWAttr() - Instead of removal, It points to the function that replaced it. Added _XMLCreateAttrib() Fixed bug with _XMLCreateRootNodeWAttr ,_XMLCreateChild[Node]WAttr() where an extra node with same name was added. Stripped extrenous comments. Removed dependency on Array.au3 (I added the func from Array.au3 and renamed it to avoid conflicts.)Edit: Jun 8, 2007 Fixed a namespace bug in _XMLCreateChildNode() and _XMLCreateChildNodeWAttr()Edit: July 12, 2007 Changed version number displayed on this page to reflect latest version.Edit: July 13, 2007Fixed example script.Edit: July 20, 2007Fixed a bug where a failed _XMLFileOpen() return an empty objectAdded an object check to applicable functions.Edit: Aug 8, 2007Added _XMLSetAutoSave() to turn off/on forced saving. -- Thanks drlava. Added check for previous creation of COM error handler. --Thanks Lukasz SulejaEdit: Aug 27, 2007Changed order of properties created on file open to correct behaviour with namespaces.Edit: Aug 31,2007 Fixed bug where _XMLUpdatedField would inadvertantly erase child nodes.Edit: Sep 07,2007Fixed _XMLDeleteNode bug where non-existant node cause COM error.Added _XMLNodeExist function to check for the existence of node or nodes matching the specified pathEdit: Jan 05,2008Fixed header documentation for _XMLGetAttrib. It returns the requested attribute if found. Not an array.Edit: Feb 25,2008Fixed dimensioning bug in _XMLGetChildren --Thanks obliqueEdit: Mar 05,2008 Return values fixed for the following functions: --Thanks oblique_XMLFileOpen ,_XMLLoadXML,_XMLCreateFileDocumentation fixed for _XMLGetNodeCount,_XMLGetChildren --Thanks obliqueEdit: Mar 07,2008 Small changes.Fixed an issue pointed out by lgr. ** latest version 1.0.3.87 ** Total downloads: I have moved most of my code to google code. and dispensed with the dynamic ip service.Download here:_XMLDomWrapper.au3SVN code is here. Edited August 13, 2010 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Stumpii Posted January 10, 2006 Share Posted January 10, 2006 Great work! This has saved me alot of time and energy. I have one suggestion though as your code not work correctly for the XML file that I am using. I have an XML file with the following data: <?xml version="1.0"?> <WORKBENCH_PROJECT> <Projects> <Project UID="AJ95UX`/9_```#+'=L0@!```?P```0" closed="false" active="true" approved="false" start="2006-01-09T08:00:00" openForTimeEntry="true" format="0" trackMode="0" finish="2006-01-09T17:00:00" priority="10" finishImposed="false" cpmType="0" name="Project1" startImposed="false" program="false"> <Tasks> <Task UID="1_AJ5\([`/5_```#+'=L0@!```?P```0" start="2006-01-09T08:00:00" proxy="false" critical="false" status="0" outlineLevel="1" finish="2006-01-09T17:00:00" summary="true" milestone="false" name="first" fixed="false" locked="false" key="false" percComp="0.0" unplanned="false"/> <Task UID="2_AJ?O93`?1_```#+'=L0@!```?P```0" start="2006-01-09T08:00:00" proxy="false" critical="false" status="0" outlineLevel="2" finish="2006-01-09T17:00:00" summary="false" milestone="false" name="second" fixed="false" locked="false" key="false" percComp="0.0" unplanned="false"/> </Tasks> </Project> </Projects> </WORKBENCH_PROJECT> As there are two TASK nodes under the TASKS node, I could not find any way to access the TASK nodes with your code, so I modified one the UDFs in your code such that I can select which of the nodes I wish to access by index instead of name. I have posted the code below. If your code allows you to do this, then let me know the error of my ways. Func _XMLGetAllAttrib($strXPath, ByRef $aName, ByRef $aValue, $strQry = "", $NodeIndex = 0) Local $objNodeList, $objQueryNodes, $objNode, $arrResponse[2][1], $i, $i1 $objQueryNodes = $objDoc.documentElement.selectNodes ($strXPath & $strQry) While @error = 0 And $objQueryNodes.length > 0 $objNodeList = $objQueryNodes.item ($NodeIndex).attributes _DebugWrite("Get all attrib " & $objNodeList.length) ReDim $arrResponse[2][$objNodeList.length + 1] ReDim $aName[$objNodeList.length] ReDim $aValue[$objNodeList.length] For $i = 0 To $objNodeList.length - 1 $arrResponse[0][$i] = $objNodeList.item ($i).nodeName $arrResponse[1][$i] = $objNodeList.item ($i).Value $aName[$i] = $objNodeList.item ($i).nodeName $aValue[$i] = $objNodeList.item ($i).Value Next Return $arrResponse WEnd ; _XMLError( "Error retrieving attributes for: " & $strXPath & @CRLF & $oMyError.windescription & @CRLF & $oMyError.scriptline) _XMLError( "Error retrieving attributes for: " & $strXPath & @CRLF) SetError(1) Return -1 ; EndIf EndFunc ;==>_XMLGetAllAttrib Thank you again for you excellent work! Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
eltorro Posted January 10, 2006 Author Share Posted January 10, 2006 (edited) Stumpii, This will work with the code as is.#include <_XMLDomWrapper.au3> #include <Array.au3> ;_XMLFileOpen("C:\Program Files\AutoIt3\scripts\workbench_proj.xml") $sXmlFile = FileOpenDialog("", @ProgramFilesDir & "\autoit", "XML (*.xml)", 1) ;ConsoleWrite($sXmlFile&@lf) If @error Then MsgBox(4096, "File Open", "No file chosen") Exit Else $oOXml = "" $oOXml = _XMLFileOpen ($sXmlFile) if @error then MsgBox(4096, "File Open Error", "Error Opening File. Exiting program") Exit EndIf EndIf dim $aAttName[1],$aAttVal[1] ;get first node attribs note: using optional query string $ret = _XMLGetAllAttrib("/WORKBENCH_PROJECT/Projects/Project/Tasks/Task",$aAttName,$aAttVal,"[0]") _ArrayDisplay($aAttName,"Task[0]"); show the names _ArrayDisplay($aAttVal,"Task[0]"); show the values dim $aAttName1[1],$aAttVa1l[1] ;get second node attribs note: XPath query string attached to path ;if one was to look at the code, the func just appends the optional query string to the path anyway. $ret = _XMLGetAllAttrib("/WORKBENCH_PROJECT/Projects/Project/Tasks/Task[1]",$aAttName1,$aAttVal1) _ArrayDisplay($aAttName1,"Task[1]") _ArrayDisplay($aAttVal1,"Task[1]") Edit: Does not work. Reuse of the same arrays allowed the value to show from the previous call. ;;get nodes based on a partial match. @ is for attribs. ;$ret = _XMLGetAllAttrib("/WORKBENCH_PROJECT/Projects/Project/Tasks/Task[@UID='2_AJ?*']",$aAttName,$aAttVal) ;_ArrayDisplay($aAttName,"Task[1]") ;_ArrayDisplay($aAttVal,"Task[1]") give it a try. You should also be able to use the following:_XMLGetAllAttrib("/WORKBENCH_PROJECT/Projects/Project/Tasks/*[1]",$aAttName,$aAttVal) Let me know. And thank you for posting. I have added a couple of extra functs and I am going to re-work a couple of exisisting ones in the near future. The basic syntax and functionality should remain the same. I'll update the first post when I have completed it. Edited January 11, 2006 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Stumpii Posted January 10, 2006 Share Posted January 10, 2006 That's great. I will give it a try tonight. Look forward to the new version! Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
eltorro Posted January 11, 2006 Author Share Posted January 11, 2006 Update: working on a func that will return a node id or position based on the query. supposedly _XMLGetAllAttrib("/WORKBENCH_PROJECT/Projects/Project/Tasks/Task[starts-with(@UID,'2')]",$aAttName,$aAttVal) should return true. But is doesn't. Any Ideas? Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
eltorro Posted January 11, 2006 Author Share Posted January 11, 2006 This works _XMLGetAllAttrib("/WORKBENCH_PROJECT/Projects/Project/Tasks/Task[starts-with(@UID,2)]",$aAttName,$aAttVal) Since is starts with a numeric value I guess the quotes around the 2 aren't necessary. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Stumpii Posted January 22, 2006 Share Posted January 22, 2006 I didn't get around to checking the code you suggested as I am on a different program with a different problem I am writing a prog that creates RSS feeds and the root node needs to be <rss version="2.0">. I tried to make this with the _XMLSetAttrib function, but as it requires a path from the root, I cannot find a way to access the root itself. What I ended up hacking in the code is adding attribute variables in the _XMLCreateFile function. This then allows you to set the attributes while creating the file. Could you add this feature, or show the correct way to do it? Thanks, Stumpii Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
eltorro Posted January 23, 2006 Author Share Posted January 23, 2006 I didn't get around to checking the code you suggested as I am on a different program with a different problem I am writing a prog that creates RSS feeds and the root node needs to be <rss version="2.0">. I tried to make this with the _XMLSetAttrib function, but as it requires a path from the root, I cannot find a way to access the root itself. What I ended up hacking in the code is adding attribute variables in the _XMLCreateFile function. This then allows you to set the attributes while creating the file. Could you add this feature, or show the correct way to do it? Thanks, Stumpii Sorry for the late reply :"> As far as I can tell an attribute cannot contain a space. Try this code:#include <_XMLDomWrapper.au3> _XMLCreateFile(@scriptdir&"\RootAttrib.xml","Root",True) _XMLFileOpen(@scriptdir&"\RootAttrib.xml") _XMLCreateRootAttrib("rss_version","2.0") Exit func _XMLCreateRootAttrib($aAttr,$aVal) $objChild = $objDoc.documentElement.Attributes.setNamedItem($objDoc.createAttribute ($aAttr)) $objChild.Value = $aVal $objDoc.Save(@scriptdir&"\RootAttrib.xml") EndFunc eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Stumpii Posted January 23, 2006 Share Posted January 23, 2006 Sorry for the late reply :"> As far as I can tell an attribute cannot contain a space.eltorroSorry, didn't make myself clear. In <rss version="2.0">, rss is the root node name, version="2.0" is the attribute, so there is no problem with spaces. You code looks like it will do the trick in any case. Thanks! Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
eltorro Posted January 23, 2006 Author Share Posted January 23, 2006 Sorry, didn't make myself clear. In <rss version="2.0">, rss is the root node name, version="2.0" is the attribute, so there is no problem with spaces. You code looks like it will do the trick in any case. Thanks!Please let me know if you have any other troubles. I was hoping for more feedback so I could improve the functions.Thanks. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
DjDeep00 Posted February 6, 2006 Share Posted February 6, 2006 First of all I would like to say Greatttttttt Jobbbbbbbbb..... I love this XML DOM wrapper......but as always I am not too sure how to use it.... Here is my question: (Please see the xml for refrence below) So far I am able to update the OrderNumber, virtualTN, desiredDueDate. I am having trouble updating base:LastName, base:B authorizationName, base:StreetName, etc... Please Help.... Thanks in advance. <?xml version="1.0" encoding="UTF-8"?> <VoIPOrderRequest xmlns="werwerwerwre" xmlns:xsi="werwerwerwer" xmlns:base="werwerwer" xmlns:vBase="werwerwerwerw" xsi:schemaLocation="werwerwerr file:/home/bsmedley/src/engr/project/voipgw/src/voipgw/DefaultWebApp/dtd/VoIPOrderRequest._v4.xsd"> <Header timeStamp="2003-06-25T22:17:55Z" authTok="werwerwerw" customerId="TEST"/> <OrderNumber>******</OrderNumber> <VoIPOrderType> <vBase:ProvisionAndPort virtualTN="*********"> <vBase:VoIPInfo desiredDueDate="***********"> <vBase:Name> <base:LastName>Last</base:LastName> <base:CustomerTypeIndicator> <base:B authorizationName="Some Auth Name"/> </base:CustomerTypeIndicator> </vBase:Name> <vBase:Address> <base:StreetName>Jacksonville</base:StreetName> <base:City>City</base:City> <base:State>NJ</base:State> <base:ZIP>071111</base:ZIP> <base:Country>US</base:Country> </vBase:Address> <vBase:Authorization> <base:LOA successTimeStamp="2003-06-25T22:17:55Z"/> </vBase:Authorization> </vBase:VoIPInfo> <vBase:VoIPPortInfo portBTN="11111111" currentServiceProvider="provider" currentAccountNumber="12345" clec="bo" clientAccountNumber="43210"> <vBase:PortBlock fromTN="11111111" toTN="1111"> <base:ListingTreatment> <base:Keep/> </base:ListingTreatment> </vBase:PortBlock> <vBase:PortDirection> <base:WirelineToWireline/> </vBase:PortDirection> <vBase:PortType> <vBase:P partialPortBTN="1111111111111"/> </vBase:PortType> </vBase:VoIPPortInfo> </vBase:ProvisionAndPort> </VoIPOrderType> </VoIPOrderRequest> Link to comment Share on other sites More sharing options...
eltorro Posted February 7, 2006 Author Share Posted February 7, 2006 First of all I would like to say Greatttttttt Jobbbbbbbbb..... I love this XML DOM wrapper......but as always I am not too sure how to use it.... Here is my question: (Please see the xml for refrence below) So far I am able to update the OrderNumber, virtualTN, desiredDueDate. I am having trouble updating base:LastName, base:B authorizationName, base:StreetName, etc... Please Help.... Thanks in advance. <?xml version="1.0" encoding="UTF-8"?> <VoIPOrderRequest xmlns="werwerwerwre" xmlns:xsi="werwerwerwer" xmlns:base="werwerwer" xmlns:vBase="werwerwerwerw" xsi:schemaLocation="werwerwerr file:/home/bsmedley/src/engr/project/voipgw/src/voipgw/DefaultWebApp/dtd/VoIPOrderRequest._v4.xsd"> <Header timeStamp="2003-06-25T22:17:55Z" authTok="werwerwerw" customerId="TEST"/> <OrderNumber>******</OrderNumber> <VoIPOrderType> <vBase:ProvisionAndPort virtualTN="*********"> <vBase:VoIPInfo desiredDueDate="***********"> <vBase:Name> <base:LastName>Last</base:LastName> <base:CustomerTypeIndicator> <base:B authorizationName="Some Auth Name"/> </base:CustomerTypeIndicator> </vBase:Name> <vBase:Address> <base:StreetName>Jacksonville</base:StreetName> <base:City>City</base:City> <base:State>NJ</base:State> <base:ZIP>071111</base:ZIP> <base:Country>US</base:Country> </vBase:Address> <vBase:Authorization> <base:LOA successTimeStamp="2003-06-25T22:17:55Z"/> </vBase:Authorization> </vBase:VoIPInfo> <vBase:VoIPPortInfo portBTN="11111111" currentServiceProvider="provider" currentAccountNumber="12345" clec="bo" clientAccountNumber="43210"> <vBase:PortBlock fromTN="11111111" toTN="1111"> <base:ListingTreatment> <base:Keep/> </base:ListingTreatment> </vBase:PortBlock> <vBase:PortDirection> <base:WirelineToWireline/> </vBase:PortDirection> <vBase:PortType> <vBase:P partialPortBTN="1111111111111"/> </vBase:PortType> </vBase:VoIPPortInfo> </vBase:ProvisionAndPort> </VoIPOrderType> </VoIPOrderRequest> Try this. I'm not real familiar with namespaces but the code below works with the xml in your post. #Include <_XMLDomWrapper.au3> _SetDebug(True);show debug messages via console write $sXmlFile ="C:\Program Files\AutoIt3\scripts\voip.xml";******* put your path here. If @error Then MsgBox(4096, "File Open", "No file chosen") Else $oOXml = "" $oOXml = _XMLFileOpen($sXmlFile) EndIf ;See here: http://www.xml.com/pub/a/2004/02/25/qanda.html ;Seems that one must not use the name space URI or explicitly reference it dim $aAttrName[1],$aAttrValue[1] $ret=_XMLGetField('//vBase:ProvisionAndPort/vBase:VoIPInfo/vBase:Name/base:LastName') _ArrayDisplay($ret,"/VoIPOrderRequest/VoIPOrderType/ProvisionAndPort/VoIPInfo/Name/LastName") Redim $aAttrName[1],$aAttrValue[1] $ret=_XMLGetField('//vBase:ProvisionAndPort/vBase:VoIPInfo/vBase:Address/base:StreetName') _ArrayDisplay($ret,"/VoIPOrderRequest/VoIPOrderType/ProvisionAndPort/VoIPInfo/Address/StreetName") Redim $aAttrName[1],$aAttrValue[1] $ret =_XMLGetAllAttrib("//vBase:ProvisionAndPort/vBase:VoIPInfo/vBase:Authorization/base:LOA[@successTimeStamp]",$aAttrName,$aAttrValue) _ArrayDisplay($aAttrName,"/VoIPOrderRequest/VoIPOrderType/ProvisionAndPort/VoIPInfo/Authorization/LOA") _ArrayDisplay($aAttrValue,"/VoIPOrderRequest/VoIPOrderType/ProvisionAndPort/VoIPInfo/Authorization/LOA") Exit Hope this helps. Try googling for Xpath and namespaces for more info. Steve. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
DjDeep00 Posted February 7, 2006 Share Posted February 7, 2006 Yessssss....It works!!!!....I figured out how to do _XMLUPDATEFIELD()...Thanks once again for the quick reply. Link to comment Share on other sites More sharing options...
DjDeep00 Posted February 7, 2006 Share Posted February 7, 2006 I spoke to soon.... I am able to write to the fields perfectly where u see #####. Thanks to Steve. However how can I create the following if they dont exist in the xml? 1. <PortDirection><base:WirelineToWireline/></PortDirection> and <PortDirection><base:WirelineToWireless wirelessAcctNumber="" wirelessPIN="" wirelessSSN="111223333"/></PortDirection> (Basically if its WirelineToWireline then leave it and if it is WirelineToWireless then add the items) 2. <PortType><F/></PortType> and <PortType><P partialPortBTN="1234561111"/></PortType> (Basically if it is "F" then leave it and if it is "P" then add the field partialPortBTN) Thanks in advance. I am using the following XML: <?xml version="1.0" encoding="UTF-8"?> <VoIPOrderRequest xmlns="eee" xmlns:xsi="eee" xmlns:base="eee" xmlns:voipBase="eee" xsi:schemaLocation="eee file:/home/bsmedley/src/engr/project/voipgw/src/voipgw/DefaultWebApp/dtd/VoIPOrderRequest_v4.xsd"> <Header timeStamp="2003-06-25T22:17:55Z" authTok="eee" customerId="eee"/> <OrderNumber>##########</OrderNumber> <VoIPOrderType> <PortOnly xmlns="eee"> <voipBase:VoIPInfo desiredDueDate="############"> <voipBase:Name> <base:FirstName>############</base:FirstName> <base:LastName>############</base:LastName> <base:CustomerTypeIndicator> <base:R/> </base:CustomerTypeIndicator> </voipBase:Name> <voipBase:Address> <base:StreetNumPrefix>##########</base:StreetNumPrefix> <base:StreetNum>##########</base:StreetNum> <base:StreetNumSuffix>##########</base:StreetNumSuffix> <base:StreetPrefix>##########</base:StreetPrefix> <base:StreetName>##########</base:StreetName> <base:StreetType>##########</base:StreetType> <base:StreetSuffix>##########</base:StreetSuffix> <base:UnitInformation>##########</base:UnitInformation> <base:SecondaryLocationDesignator>##########</base:SecondaryLocationDesignator> <base:Room>##########</base:Room> <base:Floor>##########</base:Floor> <base:Building>##########</base:Building> <base:City>##########</base:City> <base:State>##########</base:State> <base:ZIP>##########</base:ZIP> <base:Country>##########</base:Country> <base:EveningPhone>##########</base:EveningPhone> <base:DaytimePhone>##########</base:DaytimePhone> <base:EmailAddress>##########</base:EmailAddress> <base:EmailAddress2>##########</base:EmailAddress2> </voipBase:Address> <voipBase:Authorization> <base:LOA successTimeStamp="2005-11-01T22:17:55Z"/> <!--<base:TPV pvn="XYZ" sentTimeStamp="2005-12-22T22:17:55Z"/>--> </voipBase:Authorization> </voipBase:VoIPInfo> <VoIPPortInfo portBTN="##########" currentServiceProvider="##########" clec="##########" clientAccountNumber="##########" currentAccountNumber="##########"> <PortBlock fromTN="##########" toTN="##########"> <base:ListingTreatment><base:Keep/></base:ListingTreatment> </PortBlock> <PortDirection><base:WirelineToWireline/></PortDirection> <!--<PortDirection><base:WirelineToWireless wirelessAcctNumber="" wirelessPIN="" wirelessSSN="111223333"/></PortDirection>--> <PortType><F/></PortType> <!--<PortType><P partialPortBTN="1234561111"/></PortType>--> </VoIPPortInfo> </PortOnly> </VoIPOrderType> </VoIPOrderRequest> Link to comment Share on other sites More sharing options...
AndreaKram Posted February 8, 2006 Share Posted February 8, 2006 (edited) Hi folks, well i am kinda new and pretty much noob And sometimes i think when i see some code,... (i should really come to the point now.... sorry i am just a girl... i love eMotes ) well... i have an XML-File and need a code which reads out some data of the XML-File and put this data into variables (so i stupid one are able to work with it :"> ) The XML-File looks like this: <drinks order="4593"> <drink id="1" prod="534" name="Milk" oid="361" dd="be_019" og_id="Drink" gid="Medium" avb="1"/> <drink id="2" prod="635" name="Coffee" oid="132" dd="be_044" og_id="Drink" gid="Hot" avb="0"/> <drink id="3" prod="157" name="Water" oid="173" dd="he_019" og_id="Drink" gid="Cold" avb="1"/> </drinks> the data i need is: id, name, og_id, gid and i have no idea how to make it,... is there anyone who please help me and give me a example or something ? (i guess i must use XML-DOM-wrapper somehow ?) Thanks for helping,.. Br, Andrea Edited February 8, 2006 by AndreaKram Link to comment Share on other sites More sharing options...
DjDeep00 Posted February 8, 2006 Share Posted February 8, 2006 Hi folks,well i am kinda new and pretty much noob And sometimes i think when i see some code,...(i should really come to the point now.... sorry i am just a girl... i love eMotes )well... i have an XML-File and need a code which reads out some data of the XML-File andput this data into variables (so i stupid one are able to work with it :"> )The XML-File looks like this:<drinks order="4593"><drink id="1" prod="534" name="Milk" oid="361" dd="be_019" og_id="Drink" gid="Medium" avb="1"/><drink id="2" prod="635" name="Coffee" oid="132" dd="be_044" og_id="Drink" gid="Hot" avb="0"/><drink id="3" prod="157" name="Water" oid="173" dd="he_019" og_id="Drink" gid="Cold" avb="1"/></drinks>the data i need is:id, name, og_id, gidand i have no idea how to make it,...is there anyone who please help me and give me a example or something ?(i guess i must use XML-DOM-wrapper somehow ?)Thanks for helping,..Br,AndreaPlease post your xml, in order to provide u an example.. Link to comment Share on other sites More sharing options...
AndreaKram Posted February 8, 2006 Share Posted February 8, 2006 Please post your xml, in order to provide u an example..Hi DjDeep,The XML-File has the following content.... i am not sure if it's standard-xml,..whatever... so it looks like:------------------ START ------------------<drinks order="4593"><drink id="1" prod="534" name="Milk" oid="361" dd="be_019" og_id="Drink" gid="Medium" avb="1"/><drink id="2" prod="635" name="Coffee" oid="132" dd="be_044" og_id="Drink" gid="Hot" avb="0"/><drink id="3" prod="157" name="Water" oid="173" dd="he_019" og_id="Drink" gid="Cold" avb="1"/></drinks>------------------- END --------------------only with more rows,...<drink id="4",...<drink id="5",..<drink id="6" and so on...Thx,Andrea Link to comment Share on other sites More sharing options...
eltorro Posted February 8, 2006 Author Share Posted February 8, 2006 Hi DjDeep, The XML-File has the following content.... i am not sure if it's standard-xml,.. whatever... so it looks like: ------------------ START ------------------ <drinks order="4593"> <drink id="1" prod="534" name="Milk" oid="361" dd="be_019" og_id="Drink" gid="Medium" avb="1"/> <drink id="2" prod="635" name="Coffee" oid="132" dd="be_044" og_id="Drink" gid="Hot" avb="0"/> <drink id="3" prod="157" name="Water" oid="173" dd="he_019" og_id="Drink" gid="Cold" avb="1"/> </drinks> ------------------- END -------------------- only with more rows,...<drink id="4",...<drink id="5",..<drink id="6" and so on... Thx, Andrea Try this code to get you started: #include <Array.au3> #Include <_XMLDomWrapper.au3> _SetDebug(True);show debug messages via console write $sXmlFile ="C:\Program Files\AutoIt3\scripts\drink.xml";******* put your path here. If @error Then MsgBox(4096, "File Open", "No file chosen") Else $oOXml = "" $oOXml = _XMLFileOpen($sXmlFile) EndIf If Not IsObj($oOXml) then MsgBox(0,"Error","No Xml file.") Exit EndIf Dim $aAttrName[1], $aAttrValue[1], $node for $x= 1 to 3 $node = _XMLGetAllAttrib ("//drinks/*["&$x-1&"]",$aAttrName,$aAttrValue ); by index, show all attribs. xml indexes are 0 based. _ArrayDisplay($aAttrName,"Attrib Names") _ArrayDisplay($aAttrValue,"Attrib Value") $node = _XMLGetAttrib("//drinks/*["&$x-1&"]","name",'[@id='&$x&']'); select node by index and where id = x MsgBox(0,"Name Where Id="&$x,$node) if @error then ExitLoop Next Exit Hope this helps. Steve Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
eltorro Posted February 8, 2006 Author Share Posted February 8, 2006 I spoke to soon.... I am able to write to the fields perfectly where u see #####. Thanks to Steve. However how can I create the following if they dont exist in the xml? 1. <PortDirection><base:WirelineToWireline/></PortDirection> and <PortDirection><base:WirelineToWireless wirelessAcctNumber="" wirelessPIN="" wirelessSSN="111223333"/></PortDirection> (Basically if its WirelineToWireline then leave it and if it is WirelineToWireless then add the items) 2. <PortType><F/></PortType> and <PortType><P partialPortBTN="1234561111"/></PortType> (Basically if it is "F" then leave it and if it is "P" then add the field partialPortBTN) Thanks in advance. I am using the following XML: <?xml version="1.0" encoding="UTF-8"?> <VoIPOrderRequest xmlns="eee" xmlns:xsi="eee" xmlns:base="eee" xmlns:voipBase="eee" xsi:schemaLocation="eee file:/home/bsmedley/src/engr/project/voipgw/src/voipgw/DefaultWebApp/dtd/VoIPOrderRequest_v4.xsd"> <Header timeStamp="2003-06-25T22:17:55Z" authTok="eee" customerId="eee"/> <OrderNumber>##########</OrderNumber> <VoIPOrderType> <PortOnly xmlns="eee"> <voipBase:VoIPInfo desiredDueDate="############"> <voipBase:Name> <base:FirstName>############</base:FirstName> <base:LastName>############</base:LastName> <base:CustomerTypeIndicator> <base:R/> </base:CustomerTypeIndicator> </voipBase:Name> <voipBase:Address> <base:StreetNumPrefix>##########</base:StreetNumPrefix> <base:StreetNum>##########</base:StreetNum> <base:StreetNumSuffix>##########</base:StreetNumSuffix> <base:StreetPrefix>##########</base:StreetPrefix> <base:StreetName>##########</base:StreetName> <base:StreetType>##########</base:StreetType> <base:StreetSuffix>##########</base:StreetSuffix> <base:UnitInformation>##########</base:UnitInformation> <base:SecondaryLocationDesignator>##########</base:SecondaryLocationDesignator> <base:Room>##########</base:Room> <base:Floor>##########</base:Floor> <base:Building>##########</base:Building> <base:City>##########</base:City> <base:State>##########</base:State> <base:ZIP>##########</base:ZIP> <base:Country>##########</base:Country> <base:EveningPhone>##########</base:EveningPhone> <base:DaytimePhone>##########</base:DaytimePhone> <base:EmailAddress>##########</base:EmailAddress> <base:EmailAddress2>##########</base:EmailAddress2> </voipBase:Address> <voipBase:Authorization> <base:LOA successTimeStamp="2005-11-01T22:17:55Z"/> <!--<base:TPV pvn="XYZ" sentTimeStamp="2005-12-22T22:17:55Z"/>--> </voipBase:Authorization> </voipBase:VoIPInfo> <VoIPPortInfo portBTN="##########" currentServiceProvider="##########" clec="##########" clientAccountNumber="##########" currentAccountNumber="##########"> <PortBlock fromTN="##########" toTN="##########"> <base:ListingTreatment><base:Keep/></base:ListingTreatment> </PortBlock> <PortDirection><base:WirelineToWireline/></PortDirection> <!--<PortDirection><base:WirelineToWireless wirelessAcctNumber="" wirelessPIN="" wirelessSSN="111223333"/></PortDirection>--> <PortType><F/></PortType> <!--<PortType><P partialPortBTN="1234561111"/></PortType>--> </VoIPPortInfo> </PortOnly> </VoIPOrderType> </VoIPOrderRequest> I think this is a limitation of the function. I hadn't anticipated namespaces as most of the stuff I work with doesn't use them. I changed the function below but haven't had a chance to test it. ;=============================================================================== ; Function Name: _XMLCreateChildNode ; Description: Create a child node under the specified XPath Node. ; Parameters: $path Path from root ; $node Node to add ; Syntax: _XMLCreateChildNode($path,$node) ; Author(s): Stephen Podhajecki <gehossafats@netmdc.com> ; Returns: on error set error to 1 and returns -1 ;=============================================================================== Func _XMLCreateChildNode($strXPath, $strNode, $strData = "",$strValue="") Local $objParent, $objChild, $objNodeList While @error = 0 $objNodeList = $objDoc.documentElement.selectNodes ($strXPath) If IsObj($objNodeList) Then;.length <> 0 Then ; For $objParent In $objNodeList.documentElement.selectNodes ($strXPath) For $objParent In $objNodeList $objChild = $objDoc.createNode (1, $strNode, $strValue) If $strData <> "" Then $objChild.text = $strData $objParent.appendChild ($objChild) Next $objDoc.Save ($strFile) $objParent = "" $objChild = "" Return Else ExitLoop EndIf WEnd ; _XMLError( "Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF & $oMyError.windescription) _XMLError( "Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF) SetError(1) Return -1 EndFunc ;==>_XMLCreateChildNode I added an optional value where someone could enter the namespace. Xmldoc.createNode("element","foo", "x-schema:fooSchema.xml") so _XMLCreateChildNode(path,node,nodevalue,"x-schema:yourschema.xml") Like I said I haven't had a chance to test it yet. Pleae try it and see. Steve Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
DjDeep00 Posted February 8, 2006 Share Posted February 8, 2006 Hi Steve, Sorry for troubling u..but I am not able to create it: <PortType><P partialPortBTN="1234561111"/></PortType> Can u please post an example? 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