Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Formatting XML Output

Hello:

I'm looking to create an XML Document with that will look something like this...
<Element_1>
    <Element_2>open</Element_2>
</Element_1>

My current code (which is pasted below..) is currently giving me the following...
<Element_1>
    <Element_2 Element_2="open" />
</Element_1>

I know i'm missing the boat somewhere...

Thanks in advance...

my VS.NET 2003 code...

    Private Sub CreateXML()
        Dim MyXML As New Xml.XmlDocument
        Dim Elemt1 As Xml.XmlElement
        Dim Elemt2 As Xml.XmlElement

        MyXML = New Xml.XmlDocument

        Elemt1 = MyXML.CreateElement("Element_1")
        Elemt2 = MyXML.CreateElement("Element_2")
        Elemt2.SetAttribute("Element_2", "open")

        MyXML.AppendChild(Elemt1)
        Elemt1.AppendChild(Elemt2)

        MyXML.Save("C:\xmltest.xml")
    End Sub
0
mhertzDEV
Asked:
mhertzDEV
  • 2
1 Solution
 
kalyan258Commented:
Thats because you add the Elemt2 at an attribute - you should add it as childNode

use this one

Private Sub CreateXML()
        Dim MyXML As New Xml.XmlDocument
        Dim Elemt1 As Xml.XmlElement
        Dim Elemt2 As Xml.XmlNode

        MyXML = New Xml.XmlDocument

        Elemt1 = MyXML.CreateElement("Element_1")
        Elemt2 = MyXML.CreateElement("Element_2")

        Elemt1.AppendChild(Elemt2)
        Elemt2.AppendChild(MyXML.CreateTextNode("open"))

        MyXML.AppendChild(Elemt1)
        MyXML.Save("C:\xmltest.xml")
    End Sub

Will work.
0
 
kalyan258Commented:
It created a solution like this

<Element_1>
  <Element_2>open</Element_2>
</Element_1>

under C:\xmltest.xml

should also work for you - if you have added it as AppendChild and as textNode - your program is also correct.

Cheers.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now