Results 1 to 8 of 8

Thread: xml, help?!

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Posts
    61

    xml, help?!

    hi,

    how can i load a xml file, then be able to add, delete, rename nodes from a windows form? it would be nice if someone could send me some sample code, thanks

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    top of the mountain
    Posts
    234
    Here we go:

    dim xmlDoc As New XmlDocument()
    '*load xml file
    xmlDoc.Load("c:\some.xml")
    '*find node
    dim node1 as xmlelement
    node1=rootNode.SelectSingleNode("child::somenode")
    dim str as string
    '*get text from node
    str=node1.innertext
    '* set some text to node and save xml file
    node1.innertext="some text"
    xmlDoc.save("c:\some.xml")

    I hope that helps.

    regard j

  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Posts
    61
    thanks,

    and how do we add and remove a complete node?

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Adding and removing work a lot like in a normal collection. You can select a node and then use Remove to remove it. To add then select the parent of the node you want to add then create and append the new node. Check out the XMLDocument object methods or documentation and you should be able to figure it out.

  5. #5

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Posts
    61
    what if we have something like :
    <parent>
    <child id=1/>
    <child id=3/>
    <child id=4/>
    </parent>

    and wanted to add a child node , between 1 and 3 ( <child id=2/> ), is it possible?

    ( the order is important in my case )
    thanks again

  6. #6

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Posts
    61
    and can we find out how deep are xml file is ??? ( the depth of the deepest node )

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It can be hard (or if not I don't knwo how) to control the physical order of the nodes but IDs can be ordered easy enough. I believe there is an Insert or InsertAt method that you can use to try and control the physical order. Primarily what is reserved is the hierarchy structure, child to parent and so on. Really the key to getting tricky with it is learning XPath queries.

    http://www.zvon.org/xxl/XPathTutoria.../example1.html

    http://www.w3.org/TR/xpath

    If you have some sample xml data you can post or upload then I can probably help a little more.

  8. #8
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    The DOM Object is a very powerful xml tool. Everything you are describing pertains to retrieving the current node. Once you have a pointer to the node, you add, remove, insert before, after, etc.. I have extensive experience with xml / xslt / dom, so feel free to ask and questions and/or need examples.

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