LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-17-2005, 12:50 PM   #1
pld
Member
 
Registered: Jun 2003
Location: Southern US
Distribution: Ubuntu 5.10
Posts: 206

Rep: Reputation: 30
XML question multiple parents for child element


Hi all,

I have some XML that I am generating, and I am trying to decide on a structure for the data. I bascially have multiple children elements that may fall under multiple parents like this:

Code:
...
<field_name>
     <mine>some data</mine>
     <theirs>some data</theirs>
</field_name>
<no_of_chars>
     <mine>55</mine>
     <theirs>65</theirs>
</no_of_chars>
Can anyone see why this might be a problem, or should I give a unique name to the children relating to their parents in some way? Maybe like:


Code:
...
<field_name>
     <mine_name>some data</mine_name>
     <theirs_name>some data</theirs_name>
</field_name>
<no_of_chars>
     <mine_chars>55</mine_chars>
     <theirs_chars>65</theirs_chars>
</no_of_chars>
any thoughts here? I am kinda new to XML, so I am not sure if this would be okay... Would a parser understand that an element with a certain name is for that parent/child relationship only?
 
Old 03-17-2005, 02:14 PM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
A child element belongs solely to it's parent. As well, parents can have the same named children, and they won't overlap with other parents. However, if you provide parents, of the same child, with the same name, those parents will combine their data into one segment.. at least, perl's XML::Simple does this.. I would assume that other parsers would do the same thing.

like:
Code:
<beans>
  <bacon>
    <potato> Please! </potato>
    <sandwich> Pimento </sandwich>
  </bacon>
  <bacon>
    <descrip> This will cojoin with previous 'bacon' </descrip>
  </bacon>
  <salad>
    <potato>  However, this child is unique to 'salad' </potato>
  </salad>
</beans>
Anyone else have any ideas?

Last edited by TheLinuxDuck; 03-17-2005 at 02:16 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
Need help to strip XML & XSL tags from multiple files dfrechet Programming 9 10-12-2005 06:52 AM
point / STL vector, change element question true_atlantis Programming 1 09-17-2005 01:46 PM
PHP - XML error: junk after document element at line... jimieee Programming 2 04-27-2004 11:16 AM
Question on forking a child process brianvdc Programming 2 10-16-2003 04:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration