Results 1 to 8 of 8

Thread: XML with VB

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432

    XML with VB

    Hello can some one help me with this I need to get a XML pages code and display it in some labels

    Code:
    <!---FileName: UserList.xml---!>
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <note ID="001">
    <to>John</to>
    <from>Jo</from>
    <heading>Hello</heading>
    <body>Some text Here<body>
    </note>


    <to> = lblTo
    <From>=lblFrom
    <header=lblHeader
    <body>=lblBody


    some one help me out please

  2. #2
    Member
    Join Date
    Aug 2001
    Posts
    33
    Sorry I can't help you with that one

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    add a reference to the Microsoft XML object

    Code:
    Dim xmlDoc As MSXML.DOMDocument
    Dim xmlRoot As MSXML.IXMLDOMNode
    
    Set xmlDoc = New MSXML.DOMDocument
    xmlDoc.async = False
    xmlDoc.Load App.Path & "\system\ServerConfig.xml"
    Set xmlRoot = xmlDoc.selectSingleNode("VegaCOMM/Config")
    
    txtServerName.Text = xmlRoot.selectSingleNode("ServerName").Text
    txtAdminName.Text = xmlRoot.selectSingleNode("AdminName").Text
    txtMaxClients.Text = xmlRoot.selectSingleNode("MaxUsers").Text
    that is for a document that looks like this


    Code:
    <VegaCOMM>
    	<Config>
    		<ServerName>VegaCOMM Public Server</ServerName>
    		<AdminName>Chris Andersen</AdminName>
    		<MaxUsers>50</MaxUsers>
    		<ForumMessageDays>15</ForumMessageDays>
    		<ServerNews>Welcome To The VegaCOMM Public Server</ServerNews>
    	</Config>
    	<BannedIPs>
    		<IP>333.45.33.21</IP>
    		<IP>567.77.34.6</IP>
    	</BannedIPs>
    	<HandleFilter>
    		<Handle/>
    	</HandleFilter>
    </VegaCOMM>
    now with your xml having this
    <?xml version="1.0" encoding="ISO-8859-1"?>


    you may have to cahnge one line to

    Set xmlRoot = xmlDoc.firstChild.selectSingleNode("VegaCOMM/Config")

    Hope this helps
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432

    Exclamation

    Ya that will work thanks!! i know how to write to the file but how can i see if the data is alrdy in the file?

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    that is what my code does is read the file
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    Ok cool thanks will post when i get it to work


    [edit]
    with this
    mlRoot = xmlDoc.selectSingleNode("VegaCOMM/Config")
    would i have to do this

    <note ID="001">
    mlRoot = xmlDoc.selectSingleNode("note/ID=001")
    or should i do like
    <note>
    <ID=001>
    mlRoot = xmlDoc.selectSingleNode("note/ID=001")
    Last edited by 308holes; Feb 28th, 2002 at 05:35 PM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    tryed that and im getting errors i dont think i have the XML control

    VB Code:
    1. Private Sub cmdRead_Click()
    2. Dim xmlDoc As MSXML.DOMDocument
    3. Dim xmlRoot As MSXML.IXMLDOMNode
    4.  
    5. Set xmlDoc = New MSXML.DOMDocument
    6. xmlDoc.async = False
    7. xmlDoc.Load App.Path & "C:\Documents and Settings\Owner\My Documents\MIC\first.xml"
    8. Set xmlRoot = xmlDoc.selectSingleNode("note/ID=001")
    9. 'Set xmlRoot = xmlDoc.firstChild.selectSingleNode("note/ID=001")
    10.  
    11. txtName. Text = xmlRoot.selectSingleNode("Name").Text
    12.  
    13. End Sub

    its telling me User-Definded type is nto definded for
    Dim xmlDoc As MSXML.DOMDocument
    Dim xmlRoot As MSXML.IXMLDOMNode
    Last edited by 308holes; Feb 28th, 2002 at 06:30 PM.

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    refer to my PM to you about the control..

    a note..

    mlRoot = xmlDoc.selectSingleNode("note/ID=001")

    would not work..just say note

    mlRoot = xmlDoc.selectSingleNode("note")

    ID=001 is an attribute of the note Node, not another Node below note
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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