Results 1 to 6 of 6

Thread: VBScript with XML

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    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 2012
    Posts
    8,245

    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

    Thread Starter
    New Member
    Join Date
    Jul 2012
    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
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    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 | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    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

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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

    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
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: VBScript with XML

    Thread moved to the ASP, VB Script Forum.

Posting Permissions

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



Click Here to Expand Forum to Full Width