weaponx Posted April 14, 2009 Share Posted April 14, 2009 This is very basic. _GetFirstValue('/Test/Player/Player2') ;Get the first real value returned from the _XMLGetValue() return array. Func _GetFirstValue($node) $ret_val = _XMLGetValue($node) If IsArray($ret_val) Then Return ($ret_val[1]) Else Return SetError(1,3,0) EndIf EndFunc Link to comment Share on other sites More sharing options...
BrettF Posted April 14, 2009 Share Posted April 14, 2009 Hey weaponx. Whats the best way to read these to an array? expandcollapse popup<key>3120</key> <dict> <key>Track ID</key><integer>3120</integer> <key>Name</key><string>300</string> <key>Kind</key><string>MPEG-4 video file</string> <key>Size</key><integer>733676369</integer> <key>Total Time</key><integer>6660352</integer> <key>Date Modified</key><date>2007-05-14T10:31:06Z</date> <key>Date Added</key><date>2009-01-05T00:38:02Z</date> <key>Bit Rate</key><integer>127</integer> <key>Artwork Count</key><integer>1</integer> <key>Persistent ID</key><string>04E72A70DDD4DE36</string> <key>Track Type</key><string>File</string> <key>Has Video</key><true/> <key>HD</key><false/> <key>Video Width</key><integer>320</integer> <key>Video Height</key><integer>240</integer> <key>Movie</key><true/> <key>Location</key><string>file://localhost/C:/Documents%20and%20Settings/Administrator/My%20Documents/My%20Videos/300.mp4</string> <key>File Folder Count</key><integer>-1</integer> <key>Library Folder Count</key><integer>-1</integer> </dict> <key>3122</key> <dict> <key>Track ID</key><integer>3122</integer> <key>Name</key><string>AMERICAN_PIE_THE_NAKED_MILE</string> <key>Kind</key><string>MPEG-4 video file</string> <key>Size</key><integer>500521251</integer> <key>Total Time</key><integer>5857280</integer> <key>Date Modified</key><date>2007-12-20T10:03:12Z</date> <key>Date Added</key><date>2009-01-05T00:38:03Z</date> <key>Bit Rate</key><integer>79</integer> <key>Artwork Count</key><integer>1</integer> <key>Persistent ID</key><string>04E72A70DDD4DE39</string> <key>Track Type</key><string>File</string> <key>Has Video</key><true/> <key>HD</key><false/> <key>Video Width</key><integer>320</integer> <key>Video Height</key><integer>240</integer> <key>Movie</key><true/> It's from my iTunes Music Library.xml file if that helps. Would this UDF be the best for it? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
weaponx Posted April 14, 2009 Share Posted April 14, 2009 I posted some code before that read from itunes xml, in a different topic:http://www.autoitscript.com/forum/index.ph...5&hl=itunes Link to comment Share on other sites More sharing options...
BrettF Posted April 15, 2009 Share Posted April 15, 2009 Thanks! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
enkriptix Posted April 15, 2009 Share Posted April 15, 2009 Okay, so I'm getting data from xml <myxml> <data number=1> <value>fhfh</value> </data> <data number=2> <value>hjgj</value> </data> </myxml> and I can get value "data/value", but it always returns the first "data" node value. Is there any way I can have it return the values from the second instance of "data" (There is a namespace issue, so I had to do the following: Func _XMLGetData($file,$node,$child) Dim $i, $num, $max, $array, $XML_Path, $value _XMLFileOpen($file) $XML_Path = "//*[local-name()='" & $node & "']" $array = _XMLGetChildren($XML_Path) $max = UBound($array) For $i = 1 To $max - 1 If $array[$i][0] = $child Then $num = $i EndIf Next $value = $array[$num][1] Return $value EndFunc ;==>_XMLGetData ) Any suggestions? Free software reviews, suggestions, and computer help: The Free Man's Blog. Link to comment Share on other sites More sharing options...
enkriptix Posted April 15, 2009 Share Posted April 15, 2009 Okay, so I'm getting data from xml <myxml> <data number=1> <value>fhfh</value> </data> <data number=2> <value>hjgj</value> </data> </myxml> and I can get value "data/value", but it always returns the first "data" node value. Is there any way I can have it return the values from the second instance of "data" (There is a namespace issue, so I had to do the following: Func _XMLGetData($file,$node,$child) Dim $i, $num, $max, $array, $XML_Path, $value _XMLFileOpen($file) $XML_Path = "//*[local-name()='" & $node & "']" $array = _XMLGetChildren($XML_Path) $max = UBound($array) For $i = 1 To $max - 1 If $array[$i][0] = $child Then $num = $i EndIf Next $value = $array[$num][1] Return $value EndFunc ;==>_XMLGetDataoÝ÷ Ø ò²è zËb¢{?ªê-xׯz¹¢ÒØÂ+a¶¢YhÂ)àjëh×6Func _XMLGetData($file,$node,$attribXML = "",$child) Dim $i, $num, $max, $array, $XML_Path, $value _XMLFileOpen($file) $XML_Path = "//*[local-name()='" & $node & "']" & $attribXML $array = _XMLGetChildren($XML_Path) $max = UBound($array) For $i = 1 To $max - 1 If $array[$i][0] = $child Then $num = $i EndIf Next $value = $array[$num][1] Return $value EndFunc ;==>_XMLGetData With _XMLGetData("xmlfile.xml","data","[@number='2']","value") Free software reviews, suggestions, and computer help: The Free Man's Blog. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 27, 2009 Share Posted April 27, 2009 eltorro: The net-Nazis at work are blocking a proxy in your ocotillo link to the UDF in Post #1. Can we get the UDF posted to the autoitscript.com server again? Downloading it at home and bringing it in poses additional bureaucratic hassles, and it would be better to be able to get it directly as an uncompressed .au3 file on the forum site. Thanks. 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...
cyanidemonkey Posted May 7, 2009 Share Posted May 7, 2009 (edited) sorry if this has been fixed, but I had an issue with _XMLUpdateField appending CDATA instead of replacing (worked ok if text not wrapped in CDATA) so i did a wee edit to the wrapper, thought I'd post just in case someone has same issue.xml looks like:<document> <instructions><![CDATA[In this activity you will see a scene depicting an unrully meeting. Select from the available list all of the types of behaviour you believe are represented in this scene. When you have done this, click CHECK. <br/><br/>To begin click CONTINUE.]]></instructions> <feedback><![CDATA[Great Job, click NEXT to move on.]]></feedback> <feedbackContinue><![CDATA[Sorry, you have missed some of the behaviours which are represented within this scene.<br/><br/>Click CONTINUE to have another try.]]></feedbackContinue> </document>changing this in _XMLUpdateField function:If $objChild.nodetype = $NODE_TEXT Then $objChild.Text = $strData $bUpdate = True ExitLoop EndIf to this:If $objChild.nodetype = $NODE_TEXT Then $objChild.Text = $strData $bUpdate = True ExitLoop Else $objChild.Data = $strData $bUpdate = True ExitLoop EndIfSeems to have replace CDATA instead of apending a second CDATA to the node. I'm a bit of a noob with this DOMwrapper, so I'm not sure if it is a ok thing to do, or not. Edited May 7, 2009 by cyanidemonkey My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator Link to comment Share on other sites More sharing options...
TheCuz Posted May 9, 2009 Share Posted May 9, 2009 I don't know if I am the only one having this issue, but the download links for the files seem to be broken. [font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font] Link to comment Share on other sites More sharing options...
Skizmata Posted May 9, 2009 Share Posted May 9, 2009 I too am having trouble getting the files which is a shame because it seems awesome and I cant wait to try it! AutoIt changed my life. Link to comment Share on other sites More sharing options...
Gerifield Posted May 9, 2009 Share Posted May 9, 2009 I too am having trouble getting the files which is a shame because it seems awesome and I cant wait to try it!I've uploaded the ver. 1.0.3.87 on my upload site.You can download it from there:Download Sorry, but i don't speak English very well... :SExamples:SQLite with guiMake AU3 from DLL Link to comment Share on other sites More sharing options...
Skizmata Posted May 9, 2009 Share Posted May 9, 2009 Thanks for the link and all the work, so far so good. I am going to need to start using more and more xml stuff in my work reading this udf looks like a great introduction to it. AutoIt changed my life. Link to comment Share on other sites More sharing options...
eltorro Posted May 14, 2009 Author Share Posted May 14, 2009 Updated the download links in the first post. The svn link has the most current script. 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...
Sander Timmerman Posted May 20, 2009 Share Posted May 20, 2009 I really don't get it, I have the newest UDF but don't know how to get started reading this: <ReportItem> <port>netbios-ssn (139/tcp)</port> <severity>1</severity> <pluginID>11011</pluginID> <pluginName>SMB Detection</pluginName> <data>\nSynopsis :</data> </ReportItem> <ReportItem> <port>microsoft-ds (445/tcp)</port> <severity>1</severity> <pluginID>11011</pluginID> <pluginName>SMB Detection</pluginName> <data>\nSynopsis :</data> </ReportItem> Which commands within the xml udf do I have to use? First have to open the file, but then? Link to comment Share on other sites More sharing options...
weaponx Posted May 20, 2009 Share Posted May 20, 2009 I really don't get it, I have the newest UDF but don't know how to get started reading this: <ReportItem> <port>netbios-ssn (139/tcp)</port> <severity>1</severity> <pluginID>11011</pluginID> <pluginName>SMB Detection</pluginName> <data>\nSynopsis :</data> </ReportItem> <ReportItem> <port>microsoft-ds (445/tcp)</port> <severity>1</severity> <pluginID>11011</pluginID> <pluginName>SMB Detection</pluginName> <data>\nSynopsis :</data> </ReportItem> Which commands within the xml udf do I have to use? First have to open the file, but then? You use _XMLGetValue which returns an array of matching values. You can also use this function just to grab the first match: ;_XMLGetValue returns an array this will return the first element Func _GetFirstValue($node) $ret_val = _XMLGetValue($node) If IsArray($ret_val) Then Return ($ret_val[1]) Return SetError(1,3,0) EndFunc Link to comment Share on other sites More sharing options...
OmarOrn Posted May 27, 2009 Share Posted May 27, 2009 (edited) Hi i have been trying all kinds of ways to get this in a array but with out luck. i dont know if the xml file i have is in the right standard or if my code is valid so im just going to ask i have a xml code like this CODE<person> <comments>An useful comment, hopefully.</comments> <sourcedid> <source>IMS-LMS</source> <id>student_123456</id> </sourcedid> <userid>ColinS</userid> <name> <fn>Colin Smythe</fn> <prefix>Dr</prefix> </name> <demographics> <gender>2</gender> <bday>1958-03-31T00:00</bday> <disability>Blind</disability> </demographics> <email>colin@imsglobal.org</email> <url>http://www.imsglobal.org</url> <tel telnum="1">+44-114-2335007</tel> <adr> <pobox>345</pobox> <extadd>Region Court</extadd> <street>56 Grange Road</street> <locality>Guildford</locality> <pcode>GU12 5XH</pcode> <country>United Kingdom</country> </adr> <photo imgtype="image/jpg"> <extref>http://www.imsglobal.org/staff/photo.jpg</extref> </photo> <systemrole systemroletype="SysAdmin"/> <institutionrole primaryrole="Yes" institutionroletype="Administrator"/> <datasource>CSU-LMS</datasource></person> and need to sort and work from i have been trying to use al of the ways that are used hera but with out luck. can anybody help me ? best regards Edited May 27, 2009 by OmarOrn Link to comment Share on other sites More sharing options...
IcemanND Posted June 9, 2009 Share Posted June 9, 2009 I'm trying to modify the vista unattended.xml file by adding a section to it, basically I need to add the <FirstLogonCommands> section, there could be more than 2 <Synchronouscommand> sections:<?xml version="1.0" encoding="utf-8"?> <unattend xmlns="urn:schemas-microsoft-com:unattend"> <settings pass="oobeSystem"> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <FirstLogonCommands> <SynchronousCommand wcm:action="add"> <CommandLine>1st command</CommandLine> <Description>1st desc</Description> <Order>1</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> <CommandLine>2nd cmd</CommandLine> <Description>2nd desc</Description> <Order>2</Order> </SynchronousCommand> </FirstLogonCommands> </unattend> What I have so far is close:$sXMLFile = "unattend.xml" $result = _XMLFileOpen($sXMLFile, 'xmlns:un="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"') If $result = 0 Then Exit ;Set root path to LocalAccounts area of xml $path = '//un:unattend/un:settings[@pass="oobeSystem"]/un:component[@name="Microsoft-Windows-Shell-Setup"]' _XMLCreateChildNode ( $Path, "FirstLogonCommands", "", "urn:schemas-microsoft-com:unattend") _XMLCreateChildWAttr ( $Path & "/un:FirstLogonCommands", "SynchronousCommand", "wcm:action", "add","", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "CommandLine", "1st Command", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "Description", "1st Desc", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "Order", "1", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands", "SynchronousCommand", "", "urn:schemas-microsoft-com:unattend") _XMLCreateChildWAttr ( $Path & "/un:FirstLogonCommands", "SynchronousCommand", "wcm:action", "add","", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "CommandLine", "2st Command", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "Description", "2st Desc", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "Order", "2", "urn:schemas-microsoft-com:unattend") but this gives me:<FirstLogonCommands> <SynchronousCommand wcm:action="add"> <CommandLine>1st Command</CommandLine> <Description>1st Desc</Description> <Order>1</Order> <CommandLine>2st Command</CommandLine> <Description>2st Desc</Description> <Order>2</Order> </SynchronousCommand> <SynchronousCommand> <CommandLine>2st Command</CommandLine> <Description>2st Desc</Description> <Order>2</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> <CommandLine>2st Command</CommandLine> <Description>2st Desc</Description> <Order>2</Order> </SynchronousCommand> </FirstLogonCommands> Link to comment Share on other sites More sharing options...
IcemanND Posted June 10, 2009 Share Posted June 10, 2009 Figured it out. Had an extra line I forgot to remove when I change to use _XMLCreateChildWAttr, that took care of the second <SynchronousCommand> entry. And found the rest of the solution here: http://www.autoitscript.com/forum/index.ph...5781&hl=xml#include <_XMLDomWrapper.au3> $sXMLFile = "sysprep-enc.xml" $result = _XMLFileOpen($sXMLFile, 'xmlns:un="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"') If $result = 0 Then Exit ;Set root path to LocalAccounts area of xml $path = '//un:unattend/un:settings[@pass="oobeSystem"]/un:component[@name="Microsoft-Windows-Shell-Setup"]' _XMLCreateChildNode ( $Path, "FirstLogonCommands", "", "urn:schemas-microsoft-com:unattend") _XMLCreateChildWAttr ( $Path & "/un:FirstLogonCommands", "SynchronousCommand", "wcm:action", "add","", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "CommandLine", "1st Command", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "Description", "1st Desc", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand", "Order", "1", "urn:schemas-microsoft-com:unattend") _XMLCreateChildWAttr ( $Path & "/un:FirstLogonCommands", "SynchronousCommand", "wcm:action", "add","", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand[2]", "CommandLine", "2st Command", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand[2]", "Description", "2st Desc", "urn:schemas-microsoft-com:unattend") _XMLCreateChildNode ( $Path & "/un:FirstLogonCommands/un:SynchronousCommand[2]", "Order", "2", "urn:schemas-microsoft-com:unattend") Link to comment Share on other sites More sharing options...
orange Posted June 11, 2009 Share Posted June 11, 2009 (edited) Intro: Frequent Autoit user 2-3 years ago, need basic XML reading, seached forums & attempted examples, but could not get to work with my specific XML formatting. I am at my wits end trying to understand the filestructure and Xpath syntax that works or doesn't work with this wrapper. I am having difficutly reading anything from this particular file, since all the nodes are named the same. <?xml version="1.0" encoding="UTF-8"?> <xml-dump version="1.0"> <documentlist number="1"> <param1>1a</param1> <param2>2a</param2> <documents number="1"> <document id ="12341938741"> <paragraph name="First Information"> <paragraphdata name="TYPE"></paragraphdata> </paragraph> <paragraph name="Second Information"> <paragraphdata name="TYPE"></paragraphdata> </paragraph> </document> <document id ="456789321"> <paragraph name="First Information"> <paragraphdata name="TYPE"></paragraphdata> </paragraph> <paragraph name="Second Information"> <paragraphdata name="TYPE"></paragraphdata> </paragraph> </document> </documents> </documentlist> </xml-dump> Essentially, I have a list of documents that have their information stored in XML. Any help figuring out this child-node mess is greatly appreciated. Thanks. Edited June 11, 2009 by orange Link to comment Share on other sites More sharing options...
GrungeRocker Posted June 21, 2009 Share Posted June 21, 2009 Hi! I'm writing an XML-File like this: FileWrite($xml, '<DreamSys><Tiff2PDF><Section name="1">') For $i = 1 To $documents[0] FileWrite($xml, '<Tiff file="'&$documents[$i]&'"/>') Next FileWrite($xml, '</Section></Tiff2PDF></DreamSys>') Now I#m trying to read out all $documents I wrote in to it, but it won't work. Could anyone please post a way how to do it? Thanks [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] 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