NickyWilkes Posted May 6, 2010 Share Posted May 6, 2010 I am using the common XMLDomWrapper.au3 to get information out of the following xml... I need to return the following field values (123, 124, 125,126); <vehd:Group vehd:Name="OPTIONEN"> <vehd:Group vehd:Name="123"/> <vehd:Group vehd:Name="124"/> <vehd:Group vehd:Name="125"/> <vehd:Group vehd:Name="126"/> </vehd:Group> Using the functions in the XMLDomWrapper, we need to pass in the $sPath Path from root, I think this is what I am getting wrong. <?xml version="1.0" encoding="UTF-8"?> <vehd:VehicleData xmlns:vehd="http://www.siemens.com/sidis/pro/vehicledata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.siemens.com/sidis/pro/vehicledata VehicleData.xsd"> <vehd:Group vehd:Name="KEY"> <vehd:Item vehd:Name="PIN" vehd:Value="66772989383484"/> <vehd:Item vehd:Name="VIN" vehd:Value="U23NBU49023213"/> </vehd:Group> <vehd:Group vehd:Name="KOPFSATZ"> <vehd:Item vehd:Name="Kennnummer" vehd:Value="12345678"/> <vehd:Item vehd:Name="Grosshaendler" vehd:Value="BT"/> <vehd:Item vehd:Name="Modell" vehd:Value="KT1234"/> <vehd:Item vehd:Name="Farbe" vehd:Value="GH6790"/> <vehd:Item vehd:Name="Werkskennung" vehd:Value="11"/> <vehd:Item vehd:Name="Sollproduktionsjahr" vehd:Value="2010"/> <vehd:Item vehd:Name="Montagelinie" vehd:Value="12345"/> <vehd:Item vehd:Name="MotorPRNummer" vehd:Value="123"/> <vehd:Item vehd:Name="Fahrgestellnummer" vehd:Value="1234567890"/> </vehd:Group> <vehd:Group vehd:Name="OPTIONEN"> <vehd:Group vehd:Name="123"/> <vehd:Group vehd:Name="124"/> <vehd:Group vehd:Name="125"/> <vehd:Group vehd:Name="126"/> </vehd:Group> <vehd:Group vehd:Name="TEILELISTE"> <vehd:Group vehd:Name="221"> <vehd:Item vehd:Name="SZ01" vehd:Value="4H0907560"/> <vehd:Item vehd:Name="SZ02" vehd:Value="V03010003"/> <vehd:Item vehd:Name="SZ03" vehd:Value="4H0927158M"/> </vehd:Group> </vehd:Group> </vehd:VehicleData> Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 7, 2010 Share Posted May 7, 2010 I can only sympathize, having also failed to get namespace queries working in my experiments. That's not necessarily the fault of the UDF. I'm new to formatting XPath queries with namespaces in them. Not helpful, but you're not alone. 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...
JRowe Posted May 7, 2010 Share Posted May 7, 2010 #include <_XMLDOMWrapper.au3> $s_strMyXML = "my.xml" $s_xmlns = 'xmlns:vehd="http://www.siemens.com/sidis/pro/vehicledata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.siemens.com/sidis/pro/vehicledata VehicleData.xsd"' $s_strXMLFile = _XMLFileOpen($s_strMyXML, $s_xmlns) ConsoleWrite("Loaded..." & @CRLF) That should work. Namespaces just need to be added as a parameter to FileOpen. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
NickyWilkes Posted May 7, 2010 Author Share Posted May 7, 2010 Thank you for responses, reading an xml booklet (as I'm totally novice), I am pretty confident it is the XPath syntax I am getting wrong; especially after trying many different styles. I have something like; #Include <_XMLDomWrapper.au3> Call("main") func main() Local $sFile = ".\my.xml" If FileExists($sFile) Then $ret = _XMLFileOpen ($sFile) If $ret =0 then MsgBox(4096,"File Empty",$sFile) Exit EndIf ;$id = _XMLGetValue ("/vehicledata/group[3]/*") ;$id = _XMLSelectNodes("/vehicledata/group[3]/*") $id = _XMLGetChildren("/vehicledata/group[3]/*") If $id = -1 Then MsgBox(4096, "Error", "There has been a big error") Elseif $id = 0 Then MsgBox(4096, "No Data", "No Data exists") Elseif $id = 1 Then MsgBox(4096, "Object Not Passed", "Hmmm, don't get it!") Else MsgBox(4096, $id[0], $id[1]) EndIf Else MsgBox(4096,"File Not Found",$sFile) EndIf EndFunc Link to comment Share on other sites More sharing options...
NickyWilkes Posted May 10, 2010 Author Share Posted May 10, 2010 ...but this causes an error every time. ... Any further suggestions welcome please? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 10, 2010 Share Posted May 10, 2010 OK, this worked: #include <_XMLDOMWrapper.au3> #include <Array.au3> Global $sXML_File = @ScriptDir & "\Test1.xml" Global $sXML_NS = 'xmlns:vehd="http://www.siemens.com/sidis/pro/vehicledata"' Global $aRET, $iRET, $sRET $iRET = _XMLFileOpen($sXML_File, $sXML_NS) ConsoleWrite("Open: $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF) $iRET = _XMLGetNodeCount("/vehd:VehicleData/vehd:Group") ConsoleWrite("Group(s): $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF) $iRET = _XMLGetNodeCount("/vehd:VehicleData/vehd:Group[3]/vehd:Group") ConsoleWrite("Subgroup(s): $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF) For $n = 1 to $iRET $sRET = _XMLGetAttrib("/vehd:VehicleData/vehd:Group[3]/vehd:Group[" & $n & "]", "vehd:Name") ConsoleWrite("Name[" & $n & "]: " & $sRET & @LF) NextReturns: Open: $iRET = 1; @error = 0; @extended = 0 Group(s): $iRET = 4; @error = 0; @extended = 0 Subgroup(s): $iRET = 4; @error = 0; @extended = 0 Name[1]: 123 Name[2]: 124 Name[3]: 125 Name[4]: 126I wasn't expecting to have to declare the namespace in use both in the file open AND in the XPaths.Two other picked nits: 1 - Element names are always case sensitive in XML: "VehicleData" <> "vehicledata"2 - What you are after is an attribute (called "Name"), not the value. 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...
NickyWilkes Posted May 11, 2010 Author Share Posted May 11, 2010 Spot on, thank you very much. That has helped with understanding the array elements of how it is returned too. 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