jimw192 Posted January 29, 2014 Posted January 29, 2014 I'm trying to find a method of updating an xml file to increment the filename of the video by a number on each execution of the script - video2.mpg becomes video3.mpg or video14 becomes video34 ie I need to change 2 lines of the xml from <guid>http://127.0.0.1/videocontent/MRSS/Video2.mpg</guid> <media:content url="http://127.0.0.1/videocontent/MRSS/Video2.mpg" type="video/mpeg"/> to <guid>http://127.0.0.1/videocontent/MRSS/Video3.mpg</guid> <media:content url="http://127.0.0.1/videocontent/MRSS/Video3.mpg" type="video/mpeg"/> I've tried a few things but am lost... I tried XPath but getting confused with namespace elements Thanks for any help or pointers
jdelaney Posted January 29, 2014 Posted January 29, 2014 (edited) Do a forum search for XMLDOM...tons of examples, try them out, and post back specific questions with a reproducing script. example: Edited January 29, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
jimw192 Posted January 29, 2014 Author Posted January 29, 2014 Thanks, I had looked at this... the <guid> tag is ok, but the media:content tag is frustrating... I naively thought this might be a simple scripting task but it is not (for me)... I'll keep plodding away
jdelaney Posted January 29, 2014 Posted January 29, 2014 media is a namespace, try grabbing by /content IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
JohnOne Posted January 29, 2014 Posted January 29, 2014 You will benefit from posting your attempts. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
jimw192 Posted January 30, 2014 Author Posted January 30, 2014 (edited) example xml <rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0"> <channel> <title>Video MRSS</title> <description>Video Increment</description> <ttl>30</ttl> <item> <title>Video2</title> <link> http://127.0.0.1/videocontent/MRSS/Video2.mpg </link> <description>Video2</description> <guid>http://127.0.0.1/videocontent/MRSS/Video2.mpg</guid> <media:content url="http://127.0.0.1/videocontent/MRSS/Video2.mpg" type="video/mpeg"/> </item> </channel> </rss> trying to read media:content with linked example $strXMLStructure = "//rss/channel/item" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load(@ScriptDir & "\VidTest1.xml") $oVideoFileName = $oXML.selectNodes($strXMLStructure) For $oVideoFileName In $oVideoFileName $oGUID = $oVideoFileName.selectSingleNode("./guid") $oContent = $oVideoFileName.selectSingleNode("./content") ConsoleWrite($oContent.text & @TAB & @CRLF ) ConsoleWrite($oGUID.text & @TAB & @CRLF ) Next First ConsoleWrite is empty line 2nd is correct tag value Edited January 30, 2014 by jimw192
jdelaney Posted January 30, 2014 Posted January 30, 2014 (edited) Work around for the namespace issue: $strXMLStructure = "//rss/channel/item" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load(@ScriptDir & "\VidTest1.xml") $oVideoFileName_Col = $oXML.selectNodes($strXMLStructure) For $oVideoFileName In $oVideoFileName_Col For $oNode In $oVideoFileName.childnodes ConsoleWrite($oNode.nodename & " " & $oNode.text & @CRLF ) If String($oNode.nodename) = "media:content" Then ConsoleWrite(@TAB & "attributes: " & $oNode.getattribute("url") & @CRLF) ConsoleWrite(@TAB & "attributes: " & $oNode.getattribute("type") & @CRLF) EndIf Next Next This does work after all: $strXMLStructure = "//rss/channel/item" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load(@ScriptDir & "\VidTest1.xml") $oVideoFileName_Col = $oXML.selectNodes($strXMLStructure) For $oVideoFileName In $oVideoFileName_Col ConsoleWrite($oVideoFileName.xml & @CRLF) $oGUID = $oVideoFileName.selectSingleNode("./guid") $oContent = $oVideoFileName.selectSingleNode("./media:content") ConsoleWrite($oGUID.Text & @CRLF) ConsoleWrite($oContent.getattribute("url") & @CRLF) Next btw, my xml file: <?xml version="1.0"?> <rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0"> <channel> <title>Video MRSS</title> <description>Video Increment</description> <ttl>30</ttl> <item> <title>Video2</title> <link> http://127.0.0.1/videocontent/MRSS/Video2.mpg </link> <description>Video2</description> <guid>http://127.0.0.1/videocontent/MRSS/Video2.mpg</guid> <media:content url="http://127.0.0.1/videocontent/MRSS/Video2.mpg" type="video/mpeg"/> </item> </channel> </rss> Edited January 30, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
jimw192 Posted January 30, 2014 Author Posted January 30, 2014 Thanks - that does it! Much appreciated, what is the best function for searching the array and pulling the unknown number? Arraysearch requires me to know what value I'm looking for and the position could be different. so if I know the video filename would always be "video****.mpg" where **** could be any value from 1- '000s, can I use Arraysearch to find the "video" component and then return the char beyond this, but before the ".mpg"? Then convert those char to numerics, do the maths and then write the xml tags back with the new values? Does this sound a reasonable approach? PS - not asking for this to be written, just trying to learn and get the result I need. Thanks
jdelaney Posted January 30, 2014 Posted January 30, 2014 you can use stringregexp: $string = "video9484891.mpg" $a = StringRegExp($string,"(video)(\d+)(\..*)",3) ConsoleWrite($a[1] & @CRLF) ConsoleWrite($a[0] & $a[1]+1 & $a[2] & @CRLF) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
jimw192 Posted February 3, 2014 Author Posted February 3, 2014 I've got 95% of the way there now, but need some help with the formatting for either _XMLSetAttrib("//rss/channel/item","./guid", "my new value") or _XMLUpdateField("/rss/channel/item/guid", "my new value") whatever I use as param1 for $strXPath in the function I get an Variable must be of type "Object" error I've tried "/rss/channel/item" and $oVideoFilmName and other variations and am stuck I've read about XPath and based on the xml I think it should be "/rss/channel/item" but keep getting the object error before I even get to updating the tag value
jimw192 Posted February 4, 2014 Author Posted February 4, 2014 looks like the content of _xmldomwrapper was incomplete or previous version, no longer getting object error, but both _XMLSetAttrib and _XMLUpdateField both return failure -1 Any pointers??
Solution jimw192 Posted February 4, 2014 Author Solution Posted February 4, 2014 (edited) expandcollapse popup#include "_XMLDomWrapper.au3" $strXMLStructure = "//rss/channel/item" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load(@ScriptDir & "\VidTest1.xml") $oVideoFileName_Col = $oXML.selectNodes($strXMLStructure) For $oVideoFileName In $oVideoFileName_Col $oGUID = $oVideoFileName.selectSingleNode("./guid") $oContent = $oVideoFileName.selectSingleNode("./media:content") ConsoleWrite("OLD GUID -" & $oGUID.Text & @CRLF) ConsoleWrite("OLD Content -" & $oContent.getattribute("url") & @CRLF) Local $string = $oGUID.Text ;ConsoleWrite($string & @CRLF) $a = StringRegExp($string,"(Video)(\d+)(\..*)",3) ;ConsoleWrite($a & @CRLF) Local $oGUIDNew = "http://127.0.0.1/videocontent/MRSS/" & $a[0] & $a[1]+1 & $a[2] ConsoleWrite( "New String - " & $oGUIDNew & @CRLF) ;$oGUID.Value($oGUIDNew) ;$oGUID.Text($oGUIDNew) $oGUID.nodeValue = $oGUIDNew $oContent.setattribute("url", $oGUIDNew) ;check if correct changes have been made $oGUID = $oVideoFileName.selectSingleNode("./guid"); not working!!??!! $oContent = $oVideoFileName.selectSingleNode("./media:content"); working ConsoleWrite("NEW GUID =" & $oGUID.Text & @CRLF) ConsoleWrite("NEW Content Write =" & $oContent.getattribute("url") & @CRLF) Next $oXML.save(@ScriptDir & "\VidTest1.xml") MsgBox( 1, "Complete", "Task is Complete", 5) ;but changes are not saved to xml This works for the media.content element, but will not change the guid element, tried .value .text & .setattribute but none seem to have an effect?? Edit: Solved $oGUID.Text = $oGUIDNew Thanks jdelany much appreciated Edited February 4, 2014 by jimw192
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