need some help - VBS & XML

Author Message
candymanuu

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 11/19/2011
  • Status: offline
need some help - VBS & XML Saturday, November 19, 2011 7:25 PM (permalink)
0
Hi guys,

I'm trying to make a script to work.
I have the XML file below - i have uploaded it on 3 sites:

http://www.2shared.com/do...unB67F-/xx_online.html
http://www.filedropper.com/xx_2
http://dl.transfer.ro/tra...nov-d56b8a9451cdad.zip


What I am trying to do: a vbs script so I can run it from CMD : " cscript x.vbs"
What this script should do: remove a XML node from the XML file when a specific variable is given.


Shot example1: variable = apple1 and I want to remove from the XML file the following node: 
devices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://java.sun.com" xsi:type="java:com.mysite.something"> <hostname>apple1</hostname> <mac-address>00-01-a9-00-5d-db</mac-address> <device-image>startrom.n12</device-image> <device-type>apple</device-type> </devices>

Shot example2: variable = pear1 and I want to remove 
<devices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://java.sun.com" xsi:type="java:com.mysite.something"> <hostname>pear1</hostname> <mac-address>00-01-A9-01-43-96</mac-address> <device-image>startrom.com</device-image> <device-type>pear</device-type> <comment>no comment</comment> </devices>

My vbs is not working and I do not know why, so I kinda need some help:

set xmlDoc=CreateObject("Microsoft.XMLDOM")xmlDoc.async="false"xmlDoc.load("c:\PXE_backup.xml")variable = "apple1"[/style]
for each x in xmlDoc.documentElement.childNodes  If x.nodename = "devices" Then  tt = (x.childnodes(0).text) If tt = variable then  XMLDoc.documentElement.removeChild(x) End If  End If
next

PS: why is my post looking like this ? with [style="color..." ?
[/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style]
<message edited by candymanuu on Saturday, November 19, 2011 7:32 PM>
 
#1
    ehvbs

    • Total Posts : 3321
    • Scores: 110
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    Re:need some help - VBS & XML Saturday, November 19, 2011 10:43 PM (permalink)
    0
    Start with this sample code:
    Dim sFind  : sFind     = "apple1" 
    If 1 = WScript.Arguments.Unnamed.Count Then sFind = WScript.Arguments.Unnamed( 0 )
    Dim sXPath : sXPath    = "/PXEBootDeviceCatalog/devices/hostname[.='" & sFind & "']"
    Dim sFSpec : sFSpec    = resolvePath( "..\data\xx.xml" )
    Dim oXDoc  : Set oXDoc = CreateObject( "Msxml2.DOMDocument" )
    oXDoc.setProperty "SelectionLanguage", "XPath"
    oXDoc.async = False
    oXDoc.load sFSpec

    If 0 = oXDoc.ParseError Then
    WScript.Echo sFSpec, "looks ok"
    Dim ndFnd : Set ndFnd = oXDoc.selectSingleNode( sXPath )
    If ndFnd Is Nothing Then
    WScript.Echo "|", sXPath, "| not found"
    Else
    WScript.Echo "found     |" & ndFnd.xml & "|"
    Dim ndDevices : Set ndDevices = ndFnd.parentNode
    WScript.Echo "to delete |" & ndDevices.tagName & "|"
    ndDevices.parentNode.removeChild ndDevices
    WScript.Echo "After delete:"
    WScript.Echo oXDoc.xml
    oXDoc.Save Replace( sFSpec, ".xml", "-2.xml" )
    End If
    Else
    WScript.Echo oXDoc.ParseError.Reason
    End If
    and use the XML SDK docs
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms763742%28v=vs.85%29.aspx
    to study it.
     
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9