PsaltyDS Posted August 16, 2010 Posted August 16, 2010 (edited) @lordmikkel: MSXML won't process invalid XML, which is what you posted, with all the missing end tags. Here's an attempt to clean it up, but if you can't get valid XML to start with, don't bother trying to use the UDF on it: <?xml version="1.0"?> <page Title="Storage Devices" H1="Property" H2="Value" __type__="2" > <item Property="Disk -1" > <item Property="Manufacturer" Value="Maxtor"></item> <item Property="Model" Value="MAXTOR STM3320613AS"></item> <item Property="Size" Value="320.0 GB"></item> <item Property="Firmware Version" Value="MC1H"></item> <item Property="Serial Number" Value="9SZ2WH47"></item> <item Property="Rotational Speed" Value="7200 RPM"></item> <item Property="Interface" Value="Serial ATA"></item> <item Property="Standard" Value="ATA8-ACS | ATA8-ACS version 4"></item> <item Property="Transfer Mode (Current / Max)" Value="SATA-300 / SATA-300"></item> <item Property="Features" Value="S.M.A.R.T., 48bit LBA, NCQ, AAM"></item> <item Property="Temperature" Value="44 C (111 F)"></item> <item Property="Controller Buffer Size on Drive" Value="16384 KB"></item> <item Property="Queue Depth" Value="32"></item> <item Property="Removable" Value="No"></item> </item> <item Property="Disk -2" > <item Property="Manufacturer" Value="Western Digital"></item> <item Property="Model" Value="WDC WD3200AAKS-75SBA0"></item> <item Property="Size" Value="320.0 GB"></item> <item Property="Firmware Version" Value="12.01B01"></item> <item Property="Serial Number" Value="WD-WCAPZ2972895"></item> <item Property="Interface" Value="Serial ATA"></item> <item Property="Standard" Value="ATA/ATAPI-7 | ----"></item> <item Property="Transfer Mode (Current / Max)" Value="SATA-300 / SATA-300"></item> <item Property="Features" Value="S.M.A.R.T., 48bit LBA, NCQ, AAM"></item> <item Property="Temperature" Value="37 C (98 F)"></item> <item Property="Controller Buffer Size on Drive" Value="16384 KB"></item> <item Property="Queue Depth" Value="32"></item> <item Property="Removable" Value="No"></item> </item> </page> Edited August 16, 2010 by PsaltyDS 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
lordmikkel Posted August 17, 2010 Posted August 17, 2010 @lordmikkel: MSXML won't process invalid XML, which is what you posted, with all the missing end tags. Here's an attempt to clean it up, but if you can't get valid XML to start with, don't bother trying to use the UDF on it: thank....but i got the get _XMLGetAttrib to work...but it only gave one serial no. not all..thank again for the help #include <_XMLDomWrapper.au3> $sXmlFile = _XMLFileOpen(@ScriptDir & "\t.xml") $sRet = _XMLSelectNodes('//page[@Title="Memory"]') $test = _XMLGetAttrib('//page/item[@Property="Serial Number"]', 'Value') MsgBox(0,"",$test)
PsaltyDS Posted August 17, 2010 Posted August 17, 2010 thank....but i got the get _XMLGetAttrib to work...but it only gave one serial no. not all..thank again for the help #include <_XMLDomWrapper.au3> $sXmlFile = _XMLFileOpen(@ScriptDir & "\t.xml") $sRet = _XMLSelectNodes('//page[@Title="Memory"]') $test = _XMLGetAttrib('//page/item[@Property="Serial Number"]', 'Value') MsgBox(0,"",$test) Did it now? That's a neat trick, since the XML you posted has /page[@Title='Storage Devices'], not 'Memory'. At any rate, even though you never made use of the selection from the failed _XMLSelectNodes(), I fixed it to show proper syntax. I also corrected the _XMLGetAttrib() query to display the serial numbers: #include <_XMLDomWrapper.au3> #include <Array.au3> $sXmlFile = _XMLFileOpen(@ScriptDir & "\Test1.xml") $aRET = _XMLSelectNodes('//page[@Title="Storage Devices"]') If IsArray($aRET) Then _ArrayDisplay($aRET, "Success: $aRET") Else ConsoleWrite("Error: _XMLSelectNodes() failed, $aRET = " & $aRET & @LF) EndIf $iCount = _XMLGetNodeCount("/page/item") ConsoleWrite("$iCount = " & $iCount & @LF) For $n = 1 To $iCount $test = _XMLGetAttrib('//page/item[' & $n & ']/item[@Property="Serial Number"]', 'Value') ConsoleWrite($n & ": $test = " & $test & @LF) Next Run that in SciTE to see the output in the Console pane, or change the ConsoleWrite() to something else. Note that works fine with the corrected XML in my last post. 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
wraithdu Posted August 18, 2010 Posted August 18, 2010 I downloaded the latest SVN version last night. There are many syntax issues that trigger warnings in Au3Check, one fatal error, and the AutoSave function has an error - it does not use the value passed to it, only toggles the current state. Most of the warnings are from variables being declared and not being used, in some cases the return from an object function call is assigned to a var that is never used (objAttr and objAttrVal are notable examples). Also the Format function should probably insert @CRLF instead of @CR. There are also some pretty big script breaking changes to this version that should be documented, especially the need for the FORCE parameter in the SaveFile function. I have a version that passes Au3Check if the author would like me to post it.
lordmikkel Posted August 18, 2010 Posted August 18, 2010 am sorry, i am using Gtopala.System.Info.For.Windows and exported the report to xml, am tryin to get a program to put out the serial numbers, thats why you saw the memory, thank it did work with the xml you posted but the one i posted before is the one i need it to work for... so this will be hard...i will see how to get what you posted to work for me....thank alot still
wraithdu Posted August 19, 2010 Posted August 19, 2010 Yikes, I went back over the latest SVN file... syntax is just bad unfortunately. No disrespect to the work eltorro has done, I mean the meat of it works great. But the error checking is spotty, return values are inconsistent, documentation is bad, general coding is spotty... It's really really a WIP, even the 'release' version is like this. I've cleaned up my SVN version except for return values and documentation. I've also implemented the ByRef for the XML doc, so you can open more than one at a time. I've cleaned up the syntax and error checking (I think), and done a pretty good sanity check. I mean, it's a huge UDF and needs another set of eyes to give it a GOOD looking over, but it's tons better than it was. I know I fixed a few actual errors in there too, but I can't what exactly at this point. @Psalty or eltorro If you want my working copy to look over or merge into your SVN, let me know. I'm not going to post it unless someone asks for it.
PsaltyDS Posted August 19, 2010 Posted August 19, 2010 @Psalty or eltorroIf you want my working copy to look over or merge into your SVN, let me know. I'm not going to post it unless someone asks for it.That should be directed only at eltorro. I don't have access to his sources, and nowhere near his expertise with the subject. 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
Relman Posted August 20, 2010 Posted August 20, 2010 I searched the forums for answers on this but although I found others with the same issue as me I never found a solution. Basically I wanted to add a ChildNode which contained HTML code so needed it to be CDATA, the existing function to createcdata only worked as a root node. So I modified the _XMLCreateChildNode function so it creates a Cdata value. You use it exactly the same as the function _XMLCreateChildNode, but it will just insert it as Cdata. usage; _XMLCreateChildNodeCData($path,$node) E.g. $html = "<html><body>Hello</body></html>" _XMLCreateChildNodeCData("Root/Import/Person[1]", "Resume", $html) Gives you <Root> <Import> <Person> <Resume> ![[Cdata]<html><body>Hello</body></html>]] </Resume> </Person> </Import> </Root> Just add it to your _XMLDomWrapper.au3 file. expandcollapse popup;=============================================================================== ; Function Name: _XMLCreateChildNodeCData ; Description: Create a CData child node under the specified XPath Node. ; Parameter(s): $path Path from root ; $node Node to add ; Syntax: _XMLCreateChildNodeCData($path,$node) ; Author(s): Stephen Podhajecki <gehossafats@netmdc.com> ; Return Value(s) on error set error to 1 and returns -1 ;=============================================================================== Func _XMLCreateChildNodeCData($strXPath, $strNode, $strData = "", $strNameSpc = "") If not IsObj($objDoc) then _XMLError("No object passed to function _XMLCreateChildNode") Return SetError(1,16,-1) EndIf Local $objParent, $objChild, $objNodeList $objNodeList = $objDoc.selectNodes ($strXPath) If IsObj($objNodeList) And $objNodeList.length > 0 Then For $objParent In $objNodeList If Not ($objParent.hasChildNodes ()) Then _AddFormat($objDoc, $objParent) EndIf If $strNameSpc = "" Then If Not ($objParent.namespaceURI = 0 Or $objParent.namespaceURI = "") Then $strNameSpc = $objParent.namespaceURI EndIf ;ConsoleWrite("$strNameSpc=" & $strNameSpc & @LF) $objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc) $objChild1 = $objDoc.createCDATASection ($strData) If $strData <> "" Then $objChild1 = $objDoc.createCDATASection ($strData) $objChild.appendChild ($objChild1) $objParent.appendChild ($objChild) _AddFormat($objDoc, $objParent) Next If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile) $objParent = "" $objChild = "" $objChild1 = "" Return 1 EndIf _XMLError("Error creating CData child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF) Return SetError(1,0,-1) EndFunc ;==>_XMLCreateChildNodeCData
mattschinkel Posted August 21, 2010 Posted August 21, 2010 I would like to try your XML DOM wrapper, but I don't see any example. I need to read a xml file and get info from it. Can you please post a example on your first post? I tried the example about drinks near the top of this discussion: _SetDebug(True);show debug messages via console write $sXmlFile ="C:\Program Files\AutoIt3\scripts\drink.xml";******* put your path here. $oOXml = "" $oOXml = _XMLFileOpen($sXmlFile) If Not IsObj($oOXml) then MsgBox(0,"Error","No Xml file.") Exit EndIf but I get "No Xml file." I am using autoit beta. Thanks, Matt.
PsaltyDS Posted August 23, 2010 Posted August 23, 2010 I would like to try your XML DOM wrapper, but I don't see any example. I need to read a xml file and get info from it. Can you please post a example on your first post? I tried the example about drinks near the top of this discussion: _SetDebug(True);show debug messages via console write $sXmlFile ="C:\Program Files\AutoIt3\scripts\drink.xml";******* put your path here. $oOXml = "" $oOXml = _XMLFileOpen($sXmlFile) If Not IsObj($oOXml) then MsgBox(0,"Error","No Xml file.") Exit EndIf but I get "No Xml file." I didn't look for where you found that example, but it's pretty bogus. This should work for basic creation of the file and adding a couple of nodes: #include <_XMLDOMWrapper.au3> _SetDebug(True) $sXmlFile = @ScriptDir & "\drink.xml" If FileExists($sXmlFile) Then FileDelete($sXmlFile) $iRET = _XMLCreateFile($sXmlFile, "drinks") ConsoleWrite("Debug: $iRET = " & $iRET & "; Type = " & VarGetType($iRET) & @LF) $iRET = _XMLFileOpen($sXmlFile) ConsoleWrite("Debug: $iRET = " & $iRET & "; Type = " & VarGetType($iRET) & @LF) $iRET = _XMLCreateChildNode("/drinks", "juices", "") ConsoleWrite("Debug: $iRET = " & $iRET & "; Type = " & VarGetType($iRET) & @LF) $iRET = _XMLCreateChildNode("/drinks", "sodas", "") ConsoleWrite("Debug: $iRET = " & $iRET & "; Type = " & VarGetType($iRET) & @LF) Run('Notepad.exe "' & $sXmlFile & '"') Note right off the bat that the returns are just status codes, not objects. This UDF currently keeps the objects in internal Global variables. I am using autoit beta.Say what...? The latest Beta was 3.3.5.6, while the most current version of AutoIt is 3.3.6.1 Production. The next version is most likely going to be 3.3.7.0 Beta, but that isn't out yet and it might be a while before it is. 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
Anna82 Posted October 11, 2010 Posted October 11, 2010 (edited) hi, i'm trying to parse a amazon aws response, but i get the following error: COM Error with DOM! err.discription is: An dieser Stelle wird ein Knotentest erwartet (translated by me: a node test is suggested) /ItemSearchResponse/Items/Item/<- err.windescription: Ubekannter Fehler (unkonown error) err.Number: 800200009 err.lastdllerror is: 0 err.scriptline is: 1198 err.helpfile is: err.helpcontext is: 0 here an example : <ItemSearchResponse> <Items> <Item></Item> <Item></Item> <Item></Item> </Items> </ItemSearchResponse> $xmlResultSet = _Funktion_1($request); gets the aws response ConsoleWrite(@CRLF & "ini::" & _XMLLoadXML($xmlResultSet) & @CRLF) ConsoleWrite(@CRLF &"_XmlGetNodeCount::"& _XMLGetNodeCount ("/ItemSearchResponse/Items/Item/") & @CRLF) Edited October 11, 2010 by Anna82
PsaltyDS Posted October 12, 2010 Posted October 12, 2010 (edited) The error in English is: "Node Test expected here." Remove the trailing slash on you query if you want the count of "Item" elements under "Items": #include <_XMLDOMWrapper.au3> Global $request = "", $xmlResultSet $xmlResultSet = _Funktion_1($request); gets the aws response ConsoleWrite("ini::" & _XMLLoadXML($xmlResultSet) & @CRLF) ConsoleWrite("_XmlGetNodeCount::" & _XMLGetNodeCount("/ItemSearchResponse/Items/Item") & @CRLF) Func _Funktion_1($sReq) Return "<ItemSearchResponse>" & @CRLF & _ " <Items>" & @CRLF & _ " <Item></Item>" & @CRLF & _ " <Item></Item>" & @CRLF & _ " <Item></Item>" & @CRLF & _ " </Items>" & @CRLF & _ "</ItemSearchResponse>" & @CRLF EndFunc ;==>_Funktion_1 Edited October 12, 2010 by PsaltyDS 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
KatoXY Posted October 18, 2010 Posted October 18, 2010 On my Dell computers I generated BIOS inventory files ”TaskResult.xml”Below is a part of this file:- <root>- <command name="Inventory"> <property name="SS.ExtensionTokens" value="1099511627775" errorcode="0x0" /> <property name="SS.NumberOfBootDevices" value="5" errorcode="0x0" /> <property name="Memory.Size" value="2027044" errorcode="0x0" /> <property name="PWR.LowPowerS5" value="4" errorcode="0x0" /> <property name="PWR.MultiCore" value="3" errorcode="0x0" /> <property name="PWR.WakeupOnLAN" value="6" errorcode="0x0" /> <property name="PWR.WakeupOnLANMethod" value="3" errorcode="0x0" /> <property name="PWR.ExpressCharge" value="2" errorcode="0x0" /> <property name="Drives.ParallelATAChannel5" value="0" errorcode="0x0" /> <property name="Discovery.Manufacturer" value="Dell Inc." errorcode="0x0" /> <property name="Discovery.Model" value="OptiPlex 760" errorcode="0x0" /> <property name="Configuration.PropertyOwnershipTag" value="XYZ Limited" errorcode="0x0" /> <property name="Configuration.Password" value="" errorcode="0x80004005" /> <property name="SS.BIOSDate" value="2009-04-29T00:00:00" errorcode="0x0" /> <property name="SS.BIOSVersion" value="A03" errorcode="0x0" /> <property name="SS.SystemName" value="COMPUTER110B" errorcode="0x0" /> <property name="SS.PowerMgtSupported" value="5" errorcode="0x0" /> <property name="SS.Status" value="" errorcode="0x8004100E" /> <property name="SS.ServiceTag" value="A1A1A2A3" errorcode="0x0" /> <property name="SS.SystemDescription" value="OptiPlex 760" errorcode="0x0" /> <property name="SS.AssetTag" value="Sales/623" errorcode="0x0" /> <property name="SS.ManufacturerDate" value="" errorcode="0x8004100E" /> </command>- <command name="inventory"> <property name="task" value="Succeeded." errorcode="0x0" /> </command> </root>I need script which create new file (xml, txt, csv). The name of this file have to be a value read from SS.SystemName and contain following information: SS.SystemName, SS.ServiceTag, Discovery.Model, PWR.WakeupOnLAN. Value only, without errorcode.
PsaltyDS Posted October 18, 2010 Posted October 18, 2010 (edited) I need script...We don't do that here. This web site is all about teaching helping you with problems while you learn and use AutoIt yourself. If you want to pay someone to write a script for you, it might help to open a topic in Chat and ask, but please don't do it in the support forums. You might also look at the Rent-A-Coder link in my sig. Edited October 18, 2010 by PsaltyDS 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
KatoXY Posted October 19, 2010 Posted October 19, 2010 We don't do that here. This web site is all about teachingI didn't know. Sorry.I read many posts in this forum and found many request for help write some script.I will try write something myself. If I have some problems then I will ask you.Generally I started create something but I stopped. I will read forum again. Maybe I find solution.Thanks for your answer.RegardsKatoXY
KatoXY Posted October 27, 2010 Posted October 27, 2010 Hello again, I couldnt find Edit button so I wrote new post I found solution for my earlier question. I couldnt used <_XMLDOMWrapper.au3>. I based on <String.au3> and <Array.au3> included scripts. My post is close for me
JohannesM Posted November 6, 2010 Posted November 6, 2010 (edited) Hello, I tried the _XMLCreateChildNode function, but it doesn't work. The error "Error creating child node: Items. Tv2 does not exist." shows up. Even on the example you posted. expandcollapse popup#include <Constants.au3> #include <_XMLDomWrapper.au3> ; http://www.autoitscript.com/forum/topic/19848-xml-dom-wrapper-com/ #cs $ devcon_32.exe findall *unknown* > USB\VID_0000&PID_0000\5&1EAA782A&0&4 : Unknown Device > 1 matching device(s) found. [i] das USB\VID... ist Geraeteinstanzpfad #ce Func exeDevcon($par) Local $line, $foo = Run('devcon_32.exe' & " " & $par, @SystemDir, @SW_HIDE, $STDOUT_CHILD) While True $line &= StdoutRead($foo) If @error Then ExitLoop Wend return $line EndFunc $new = exeDevcon('drivernodes *USB*') _XMLCreateFile("test.xml", "devcon", True) _XMLFileOpen ("test.xml") $aSplit = StringSplit($new, @CRLF, 3) For $i = 0 To UBound($aSplit)-1 ; Hardware ID If Not (StringLeft($aSplit[$i], 1) == ' ') Then If Not (StringLeft($aSplit[$i], 10) == 'DriverNode') Then _XMLCreateRootChild("HardwareId", $aSplit[$i]) EndIf EndIf ; Name Tag If (StringLeft(StringStripWS($aSplit[$i], 1), 5) == 'Name:') Then _XMLCreateChildNode("HardwareId", "name", $aSplit[$i]) ConsoleWrite(_XMLError()) EndIf Next Error: expandcollapse popup_XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId Error creating child node: name HardwareId does not exist. _XMLCreateRootChild:HardwareId _XMLCreateRootChild:HardwareId Thank you so far. - Johannes M. Edited November 6, 2010 by JohannesM
PsaltyDS Posted November 6, 2010 Posted November 6, 2010 Are you getting what you expect from Devcon? I tried it with the simulated input you included: #include <_XMLDomWrapper.au3> $debugging = True ; $new = exeDevcon('drivernodes *USB*') Global $sNewData = "$ devcon_32.exe findall *unknown*" & @CRLF & _ "> USB\VID_0000&PID_0000\5&1EAA782A&0&4 : Unknown Device" & @CRLF & _ "> 1 matching device(s) found." & @CRLF & _ "" & @CRLF & _ "[i] das USB\VID... ist Geraeteinstanzpfad" & @CRLF Global $sXmlfile = @ScriptDir & "\Test1.xml" _XMLCreateFile($sXmlfile, "devcon", True) _XMLFileOpen($sXmlfile) Global $aSplit = StringSplit($sNewData, @CRLF, 3) For $i = 0 To UBound($aSplit) - 1 ; Hardware ID If Not (StringLeft($aSplit[$i], 1) == ' ') Then If Not (StringLeft($aSplit[$i], 10) == 'DriverNode') Then _XMLCreateRootChild("HardwareId", $aSplit[$i]) EndIf EndIf ; Name Tag If (StringLeft(StringStripWS($aSplit[$i], 1), 5) == 'Name:') Then _XMLCreateChildNode("HardwareId", "name", $aSplit[$i]) ConsoleWrite(_XMLError()) EndIf Next Result: <?xml version="1.0"?> <devcon> <HardwareId>$ devcon_32.exe findall *unknown*</HardwareId> <HardwareId>> USB\VID_0000&PID_0000\5&1EAA782A&0&4 : Unknown Device</HardwareId> <HardwareId>> 1 matching device(s) found.</HardwareId> <HardwareId/> <HardwareId>[i] das USB\VID... ist Geraeteinstanzpfad</HardwareId> <HardwareId/> </devcon> No errors, but I can't tell if you wanted all those HardwareId elements or not. 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
WackOo Posted January 2, 2011 Posted January 2, 2011 I'm having problems reading out the XML, I'm still quite new to AutoIt, but i'm trying to make a sync tool which i need to read certain data for which is stored in an XML file,Could anyone help me out on that part?.. That's bassicly the only thing i am stuck at.
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