Results 1 to 3 of 3

Thread: XML more than one node

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    XML more than one node

    Hi all i just got this form VB at the movies example

    VB Code:
    1. Dim xmlDoc As New XmlDocument
    2.         Dim xmlDeclare As XmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes")
    3.         Dim xmlComment As XmlComment = xmlDoc.CreateComment("Created by " & Site_URL)
    4.  
    5.         Dim xmlRoot As XmlElement = xmlDoc.CreateElement("Errors")
    6.         Dim xmlPosted As XmlAttribute = xmlDoc.CreateAttribute("Posted")
    7.         Dim xmlPage As XmlElement = xmlDoc.CreateElement("PageWithError")
    8.         Dim xmlErrMsg As XmlElement = xmlDoc.CreateElement("ErrorOccurred")
    9.  
    10.         xmlDoc.InsertBefore(xmlDeclare, xmlDoc.DocumentElement)
    11.         xmlDoc.InsertAfter(xmlComment, xmlDeclare)
    12.         xmlDoc.InsertAfter(xmlRoot, xmlComment)
    13.  
    14.         xmlPosted.InnerText = Now()
    15.         xmlPage.InnerText = "page.aspx"
    16.         xmlErrMsg.InnerText = "just testing"
    17.  
    18.         xmlRoot.SetAttributeNode(xmlPosted)
    19.         xmlRoot.AppendChild(xmlPage)
    20.         xmlRoot.AppendChild(xmlErrMsg)
    21.  
    22.         xmlDoc.Save("WebSiteErrors.xml")

    it creates the xml document and node fine but i would like to have another method in my class AddChildNode()

    this will just append another node to the xml document

    what i am doing is having a class file for trapping errors

    i passed the page it errored and the string of error message
    then view the xml document in a little app im making

    thanks all

    this is currently what im getting

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <!--Created by http://www.katiya.com-->
    <Errors Posted="12/06/2004 10:58:37">
      <PageWithError>page.aspx</PageWithError>
      <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    this is what i want

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <!--Created by http://www.katiya.com-->
    <Errors Posted="12/06/2004 10:58:37">
      <PageWithError>page.aspx</PageWithError>
      <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
      <PageWithError>page.aspx</PageWithError>
      <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
      <PageWithError>page.aspx</PageWithError>
      <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
      <PageWithError>page.aspx</PageWithError>
      <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <!--Created by http://www.katiya.com-->
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    Is not a valid XML document because it has no root element. It would have to be something like this:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <!--Created by http://www.katiya.com-->
    <AllErrors>
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    <Errors Posted="12/06/2004 10:58:37">
    <PageWithError>page.aspx</PageWithError>
    <ErrorOccurred>just testing</ErrorOccurred>
    </Errors>
    </AllErrors>

    There must be one and only one master root node that everything comes off of.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here is some example code to handle working with this xml. I didn't slap any GUI on it because I just used NUnit to test it. So the code is the XMLHelper class and all of the tests are in the file test.vb which shows how to use the class. Or you can download NUnit from http://www.nunit.org to download the tester.

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