?
Solved

Formatting XML Output

Posted on 2005-03-04
2
Medium Priority
?
145 Views
Last Modified: 2013-11-18
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
Comment
Question by:mhertzDEV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 2

Accepted Solution

by:
kalyan258 earned 2000 total points
ID: 13466654
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
 
LVL 2

Expert Comment

by:kalyan258
ID: 13466670
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question