How to create a XML Document with asp.net 2.0

Discussion in 'XML' started by Dikkuuhh, Aug 21, 2006.

  1. Dikkuuhh

    Dikkuuhh Guest

    How can i create a XMLDocument??

    This is what i have:

    Dim objNode As XmlNode

    Dim objAttrib As XmlAttribute
    objNode = objXML.DocumentElement("Person")

    objAttrib = objXML.CreateAttribute("PERSONID")
    objAttrib.Value = "p7"
    objNode.Attributes.SetNamedItem(objAttrib)
    objXML.DocumentElement.AppendChild(objNode)

    Then i get an error like this:

    System.NullReferenceException: Object reference not set to an instance
    of an object.

    Can somebody help me out?
     
    Dikkuuhh, Aug 21, 2006
    #1
    1. Advertising

  2. Dikkuuhh wrote:

    > How can i create a XMLDocument??


    Dim xmlDoc As New System.Xml.XmlDocument()



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 21, 2006
    #2
    1. Advertising

  3. Dikkuuhh

    Dikkuuhh Guest

    Now this is my code:

    Dim objXML As New System.Xml.XmlDocument()
    Dim objNode As XmlNode
    Dim objAttrib As XmlAttribute
    objNode = objXML.DocumentElement("Person")

    objAttrib = objXML.CreateAttribute("PERSONID")
    objAttrib.Value = "p7"
    objNode.Attributes.SetNamedItem(objAttrib)
    objXML.DocumentElement.AppendChild(objNode)

    But i`m still getting the same error....


    Martin Honnen wrote:
    > Dikkuuhh wrote:
    >
    > > How can i create a XMLDocument??

    >
    > Dim xmlDoc As New System.Xml.XmlDocument()
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    Dikkuuhh, Aug 22, 2006
    #3
  4. Dikkuuhh wrote:


    > Dim objXML As New System.Xml.XmlDocument()


    This line creates the XmlDocument instance but it is empty, you can
    either load existing XML into it with the Load method to load from a URL
    or stream (or the LoadXml method if you have a string with the XML
    markup) or you need to populate the document with nodes by first
    creating them and inserting them as needed e.g. (watch out for line
    breaks VB does not allow but the news posting might have)

    Dim rootElement As XmlElement =
    objXML.CreateElement("some-element-name")
    Dim someElement as XmlElement =
    objXML.CreateElement("another-element-name")
    someElement.SetAttribute("attribute-name", "attribute value")
    rootElement.AppendChild(someElement)
    objXML.AppendChild(rootElement)

    objXML.Save("file.xml")

    If you still have problems then I suggest microsoft.public.dotnet.xml is
    a better place than comp.text.xml.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 22, 2006
    #4
  5. Dikkuuhh

    sjr.priyanka

    Joined:
    Oct 8, 2011
    Messages:
    4
    sjr.priyanka, Oct 20, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Westmore

    Using ASP to create a dynamic XML document

    Jon Westmore, Feb 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,731
    Kevin Spencer
    Feb 23, 2005
  2. Tony Prichard
    Replies:
    0
    Views:
    746
    Tony Prichard
    Dec 12, 2003
  3. Manish Hatwalne
    Replies:
    1
    Views:
    401
    Martin Honnen
    Jul 13, 2004
  4. Replies:
    4
    Views:
    684
  5. Krithika San
    Replies:
    3
    Views:
    339
    Marnen Laibow-Koser
    Nov 14, 2009
Loading...

Share This Page