?
Solved

How to create xml tags in the middle of child elements

Posted on 2001-06-25
3
Medium Priority
?
177 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 150 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses

850 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