Solved

How to create xml tags in the middle of child elements

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 73
Getting warning: You are about to delete 1 row(s) 9 50
Help me. 3 57
VB6 - Scroll Mouse wheel on Picturebox 13 44
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to count occurrences of each item in an array.
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…

831 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