Results 1 to 6 of 6

Thread: VBScript with XML

  1. #1
    New Member
    Join Date
    Jul 12
    Posts
    4

    VBScript with XML

    I am trying to gather a piece of data from an XML file and am getting all sorts of errors. Here is my function to grab the piece I need. I just need one piece from the XML and that is "diagCd". I am getting errors saying object required on the Set Node line and then I'm getting "expected '='" on the Set xmlDoc line when I separate it out. I am just trying to read the XML and save diagCd to the variable DX1.

    Code:
        Function DX1ToUnet(DX1, sUser, FileExists, CurrentVersion)
    Set objXMLDoc = Createobject("Microsoft.XMLDOM")
           Dim Node
    
    'objXMLDoc = CreateObject("Microsoft.XMLDOM") 
    objXMLDoc.load("C:\Documents and Settings\" & sUser & "\Local Settings\Application Data\" & CurrentVersion & "\temp.xml")
    objXMLDoc.load("temp.xml")
    Set Node = objXMLDoc.documentElement.selectSingleNode("diagCd")
    DX1 = Node.Text 
     
    msgbox DX1
    
    End Function

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,471

    Re: VBScript with XML

    I have to confess that I have absolutely no idea what you're trying to do here and none of it seems to be related to gathering a piece of data from an XML files . Can you explain what you think the code is going to do?

  3. #3
    New Member
    Join Date
    Jul 12
    Posts
    4

    Re: VBScript with XML

    I am loading the xml doc from:

    C:\Documents and Settings\" & sUser & "\Local Settings\Application Data\" & CurrentVersion & "\temp.xml

    and reading the node "diagCd" to save to variable DX1. However VBScript doesn't like it. See errors above.

  4. #4
    Burning Member Niya's Avatar
    Join Date
    Nov 11
    Posts
    3,096

    Re: VBScript with XML

    Why are you using Microsoft.XMLDOM ? Did you copy that code from somewhere ? There are better facilities in the .Net Framework for handling XML. Two of which are the XmlDocument class and the XDocument class.

    EDIT:

    What a minute.....is that VB6 code(there is no Set in VB.Net) ? If it is, its in the wrong section of the forum.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | Create Sortable BindingList(not mine) | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  5. #5
    Frenzied Member MattP's Avatar
    Join Date
    Dec 08
    Location
    WY
    Posts
    1,182

    Re: VBScript with XML

    This needs moved to the ASP VB Script section of the boards.

    The sample xml file I was working with.

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <Root>
    	<diagcd>Hello World</diagcd>
    </Root>
    The vbs file I test with.

    Code:
    Set xmlDoc = CreateObject("Microsoft.XMLDOM")
    xmlDoc.load "C:\Temp\MyFile.xml"
    
    Set node = xmlDoc.selectsinglenode("//Root/diagcd")
    
    msgbox node.Text
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  6. #6
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 99
    Location
    Sweden
    Posts
    13,401

    Re: VBScript with XML

    Thread moved to the ASP, VB Script Forum.
    Joacim Andersson
    Microsoft MVP, MCSD, MCSE, Sun Certified Java Programmer
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •