Results 1 to 5 of 5

Thread: New to XML, need help with structure.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95

    New to XML, need help with structure.

    I'm trying to create the XML equivalent of a ListDictionary or Hashtable. So what would that look like? I'm getting confused by elements, nodes, childnodes, I mean XML is designed for nesting data but I really need to keep it simple for my purposes.

    I just need to have TWO fields, name and URL, kind of like KEY and VALUE in a hashtable.

    That way a client reading the file can get a list all the available web services I specify in the file, get the name of the affiliate running the service and the web service URL associated with the affiliate.

    Any help would be appreciated. I've been getting shafted around here for a couple of days now, where are all the regulars at?

    KT

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Code:
    <myItem>
          <name>Hey</name>
          <url>http://www.gg.com</url>
    </myItem>
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Or more accuratly:
    Code:
    <myList>
          <myItem id="1">
                <name>Hey</name>
                <url>http://www.gg.com</url>
          </myItem>
          <myItem id="2">
                <name>Hey</name>
                <url>http://www.gg.com</url>
          </myItem>
          <myItem id="3">
                <name>Hey</name>
                <url>http://www.gg.com</url>
          </myItem>
          <myItem id="4">
                <name>Hey</name>
                <url>http://www.gg.com</url>
          </myItem>
    </myList>
    First thing you'll proly want in the project is the MSXML parser, wich comes in version 2-4, depending on the capabilities you want. Then it's a matter of creating a DOMDocument, creating a node, setting it as the DocumentElement of your DOMDocument object, then appending nodes to the DocumentElement.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Also to explain the xml terminology you might be confused by... Elements in the example above are <myList>, <myItem>, <name>, <url>

    An Attribute is the id = "1"

    Childnodes. A node nested in another called the parent...so myItem is a child of myList. name and url are children of myItem.

    Get it?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    Gentlmen,

    Thanks a lot for all your help! I decided to go a step further and allow each affiliate to have more than one URL for redundancy, so my XML document looks as follows:

    Code:
     <?xml version="1.0" encoding="utf-8" ?>
    <Discovery>
    	<Services name="m4DS0ft">
    		<url>http://www.blahblah.com/blah/service.asmx</url>
    	</Services>
    	<Services name="Uber1337">
    		<url>http://someurl.com</url>
    	</Services>
    </Discovery>
    Now, using the C1 components I was able to generate a dynamic command list based on this XML document at runtime.

    VB Code:
    1. Private Sub LoadNetworkList()
    2.         networkList.Clear()
    3.         xmd.Load("http://urltoxmldocument/discovery.xml")
    4.         Dim node As XmlNode = xmd.DocumentElement
    5.  
    6.         Dim count As Integer = 0
    7.         For Each node In xmd.DocumentElement.ChildNodes
    8.             Select Case node.Name
    9.                 Case "Services"
    10.                     Me.mnuNetwork.CommandLinks.Add(New C1CommandLink)
    11.                     Me.mnuNetwork.CommandLinks(count).Command = New C1Command
    12.                     Me.mnuNetwork.CommandLinks(count).Command.Text = node.Attributes(0).Value
    13.                     Me.mnuNetwork.CommandLinks(count).Command.Name = "cmdNetwork" & node.Attributes(0).Value
    14.                     networkList.Add(node.Attributes(0).Value, node.ChildNodes(0).ChildNodes(0).Value)
    15.                     count += 1
    16.             End Select
    17.         Next node
    18.     End Sub

    But now I have a new problem. Realizing I can't store values for the commands, I also added the xml data to a listdictionary where i can look it up by key. But how do I handle the click events for these runtime command buttons? like for example, m4DS0ft was an affiliate name in the xml document. so one of the commands generated at runtime was cmdNetworkm4DS0ft. How can I handle an event for a command that does not exist? Remember, I don't know that it's m4ds0ft, it could be any name. I basically want to change the web service URL when one of these is clicked.

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