jdelaney Posted October 18, 2012 Posted October 18, 2012 (edited) I have an XML file, which is the output of all the local stations scheduled tasks.It spits it out like the following:<!-- Auto10182012142651 --><Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> ...lots of data<Task>What I need is to grab Auto10182012142651, and place it as a node under <Task>...why microsoft would put the task name outside of the Task is beyond me, but whatever.1) If you know of a way to grab a comment VIA XPaths, that would work for me, or2) I'm trying to create a RegExpReplace to change the above to look like this:<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <Name>Auto10182012142651</Name>...lots of data<Task>I have this, as a jumping off point, but have problems in general...suggestions are welcomeXpath route$string = '<Tasks>' & @crlf & _ '<!-- Adobe Flash Player Updater -->' & @crlf & _ '<Task version="1.1" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">' & @crlf & _ '<Node>test</Node>' & @crlf & _ '</Task>' & @crlf & _ '</Tasks>' ; XML route $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.loadXML($string) $oCommentNodes = $oXML.selectNodes('//comment()') ; grab all comments For $oComment In $oCommentNodes $oXML2 = ObjCreate("Microsoft.XMLDOM") $oXML2.loadXML($oComment.XML) ;ConsoleWrite ( $oXML2.baseURI & @CRLF ) ;ConsoleWrite ( $oXML2.localName & @CRLF ) ;ConsoleWrite ( $oXML2.name & @CRLF ) ConsoleWrite ( $oXML2.namespaceURI & @CRLF ) ConsoleWrite ( $oXML2.nodeName & @CRLF ) ConsoleWrite ( $oXML2.nodeType & @CRLF ) ConsoleWrite ( $oXML2.nodeValue & @CRLF ) ;ConsoleWrite ( $oXML2.textContent & @CRLF ) ConsoleWrite ( $oXML2.text & @CRLF ) ;ConsoleWrite ( $oXML2.value & @CRLF ) Nextregexp route$string = '<Tasks>' & @crlf & _ '<!-- test1 -->' & @crlf & _ '<Task version="1.1" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">' & @crlf & _ '<Node>test</Node>' & @crlf & _ '</Task>' & @crlf & _ '<!-- test2 -->' & @crlf & _ '<Task version="1.1" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">' & @crlf & _ '<Node>test</Node>' & @crlf & _ '</Task>' & @crlf & _ '</Tasks>' $string = StringRegExpReplace ( $string, "<!-- (.*) -->[s]+(<Task[W|w]+mit/task"">)", "2" & "<Name>1</Name>" ) MsgBox ( 1,1,$string )edit: solved with regexp: $string = StringRegExpReplace ( $string, "s?<!-- (.*) -->s+(.*)s+", "2" & "<Name>1</Name>" )...and xpath...$oXML = ObjCreate("Microsoft.XMLDOM") $oXML.loadXML($string) $oCommentNodes = $oXML.selectNodes('//comment()') ; grab all comments For $oComment In $oCommentNodes ConsoleWrite($oComment.text & @CRLF) Nextjust needed to step back for a min Edited October 19, 2012 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.
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