Solved

How to create xml tags in the middle of child elements

Posted on 2001-06-25
3
167 Views
Last Modified: 2013-11-19
I developed a xml file in visualbasic and my code looks like this:

 ofcourse i declared all the variables, here i'm not showing.

    Set objperson = m_objDOMpeople.createElement("PERSON")
     m_objDOMpeople.appendChild objperson

  'to this create element (objPerson), add its childNodes
  Set objNewchild = m_objDOMpeople.createElement("NAME")
  objNewchild.Text = B_Name
  objperson.appendChild objNewchild
     
 Set objNewchild = m_objDOMpeople.createElement("ADDRESS")
  objNewchild.Text = B_Address
  objperson.appendChild objNewchild


I'm getting resulting xml file as:

<Person>
<Name>sdfdsf</Name>
<ADDRESS>1232,sdfsdfs</ADDRESS>
</Person>

What I want is how to create a xml tag in the middle like:

<Person>
<Name>sdfdsf</Name>
<ADDRESS Detail>
<ADDRESS>1232,sdfsdfs</ADDRESS>
</ADDRESS Detail>
</Person>

If you observe both codes you will see difference, i want to acheive the second one. I tried several ways but it is not working.

0
Comment
Question by:vmandem
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6225062
The main problem is that "ADDRESS Detail" is an invalid element name.  So if we change that to "ADDRESS_Detail" the following code should achieve the desired result:

Set objperson = m_objDOMpeople.createElement("PERSON")
m_objDOMpeople.appendChild objperson

'to this create element (objPerson), add its childNodes
Set objNewchild = m_objDOMpeople.createElement("NAME")
objNewchild.Text = B_Name
objperson.appendChild objNewchild

'DIM objNewAddress the same way as objNewChild,
'and add the following two lines
Set objNewAddress = m_objDOMpeople.createElement("ADDRESS_Detail")
objPerson.appendChild objNewAddress
     
Set objNewchild = m_objDOMpeople.createElement("ADDRESS")
objNewchild.Text = B_Address
objperson.appendChild objNewAddress   'Changed this line

Hope this helps,
Anthony
0
 

Author Comment

by:vmandem
ID: 6225157
anthony

It didn't work like that i got the result like this:

<PERSON>
<NAME>666666</NAME>
  <TELEPHONE>45645654645</TELEPHONE>
  <ADDRESS_DETAIL />
  <ADDRESS />
</PERSON>

i tried the same way you said, i declared the objnewaddress as ixmldomelement same way as objnewchild.

I'm not getting any value for address too, it was coming before but now not coming. The other thing is there is no closing tag for Address_detail and it shows<address_detail/>, i don't no why it is showing like that.

Please correct me.

Thanks
Vijay
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 50 total points
ID: 6225210
You are absolutely right.  It was a typo on my part:

The line:
objperson.appendChild objNewAddress   'Changed this line

Should read:
objNewAddress.appendChild objNewChild   'Changed this line

Sorry about that,
Anthony
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now