Solved

How to create xml tags in the middle of child elements

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to dynamically set the form action using jQuery.

840 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