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

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top