Results 1 to 5 of 5

Thread: XML - Appending [Resolved]

Threaded View

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    XML - Appending [Resolved]

    I have an XML file with the following structure:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <family>
      <name gender="Male">
        <firstname>Tom</firstname>
        <lastname>Smith</lastname>
      </name>
      <name gender="Female">
        <firstname>Dale</firstname>
        <lastname>Doorknob</lastname>
      </name>
    </family>
    Now I'd like to append a node to this through code only. Here is what I have so far:

    VB Code:
    1. Dim XMLd As New XmlDocument
    2.        
    3.  
    4.  
    5.         XMLd.Load(Server.MapPath("family.xml")) 'this is fine, no problem with mapping!
    6.        
    7.  
    8.         Dim xmlEl As XmlElement = XMLd.CreateElement("name")
    9.         Dim xmlAttr As XmlAttribute = XMLd.CreateAttribute("gender")
    10.         xmlAttr.Value = "male"
    11.         xmlEl.Attributes.Append(xmlAttr)
    12.  
    13.         xmlEl.InnerXml = "<firstname></firstname><lastname></lastname>"
    14.  
    15.         Dim txtNode As XmlText = XMLd.CreateTextNode("Alfed E")
    16.  
    17.         xmlEl.FirstChild.AppendChild(txtNode)
    18.         xmlEl.Item("lastname").InnerText = "Neumann"
    19.  
    20.         XMLd.DocumentElement.AppendChild(xmlEl)


    When I run the code, very simply, this is what happens:

    Nothing.

    Absolutely nothing. Zilch. Nada. Zero! (Yes, with the exclamation)

    So what am I missing? Even an existing example similar to this would be helpful.
    Last edited by mendhak; Aug 2nd, 2004 at 02:14 AM.

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