Jump to content

Help with script


jimw192
 Share

Go to solution Solved by jimw192,

Recommended Posts

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

<media:content url="http://127.0.0.1/videocontent/MRSS/Video2.mpg" type="video/mpeg"/>

 

to

<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

Link to comment
Share on other sites

Do a forum search for XMLDOM...tons of examples, try them out, and post back specific questions with a reproducing script.

example:

Edited 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.
Link to comment
Share on other sites

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 by jimw192
Link to comment
Share on other sites

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 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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Solution

#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 by jimw192
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...