General xml question from newbie

J

js

Can a child tag have the same name as its parent?

eg

<root>
<aaa>
</aaa>

<bbb>
<ccc>
</ccc>
</bbb>

<ddd>
<ddd>
</ddd>
<ddd>
</ddd>
</ddd>
</root>

Brad.
 
F

Francesc Guim Bernat

hi Brad,

There is no problem that a child tag has the same name as its parent.
You're sample looks right, it's a well-formed XML.

Francesc
 
M

Marcio DeBarros

In the same line of question....

Can a tag under different parents have the same name ?

E.g.:

<root>
<username>
</username>
<message>
<username>
</username>
</message>

</root>

Thanks

MD.
 
M

Martin Boehm

Can a tag under different parents have the same name ?

E.g.:

<root>
<username></username>
<message>
<username></username>
</message>
</root>

I reformatted your code a little for easier reading.
Of course this XML fragment is well-formed. If it is valid depends on
what you want, e.g. what your Schema/DTD requires (if you decide to
supply one).

As far as well-formedness goes, you can put any element into any
element, as long as you do not break nesting, like:

<root>
<username>
<message></username>
</message>
</root>

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top