Solved

How to create xml tags in the middle of child elements

Posted on 2001-06-25
3
173 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
[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
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

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!

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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