Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Can be multiple instances of element used as the root element?

Reply
Thread Tools

Can be multiple instances of element used as the root element?

 
 
VK
Guest
Posts: n/a
 
      10-29-2006
Can be multiple instances of element used as the root element?

That's a curly way of asking, but I did not come up with a better
sentence, sorry. What I mean is with a document like:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>Content</element>
<root><element>Content</element></root>
<element>Content</element>
</root>

so <root> elements is used not only as a root element but inside the
document as well. Is this a valid (in the wide sense) markup?

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-29-2006
VK wrote:


> What I mean is with a document like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <element>Content</element>
> <root><element>Content</element></root>
> <element>Content</element>
> </root>
>
> so <root> elements is used not only as a root element but inside the
> document as well. Is this a valid (in the wide sense) markup?


It is well-formed XML. Validity of markup can only be assessed if you
have a DTD or a schema against which to validate and your example does
not show any schema.
An example of what you have (e.g. the same element type as the root
element and as a possible child of the root element) is SVG 1.1 for
instance where the root element is an |svg| element in the namespace
http://www.w3.org/2000/svg and can contain further such |svg| elements.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      10-29-2006
VK wrote:
> Can be multiple instances of element used as the root element?
>
> That's a curly way of asking, but I did not come up with a better
> sentence, sorry. What I mean is with a document like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <element>Content</element>
> <root><element>Content</element></root>
> <element>Content</element>
> </root>


Why not just run a parser on it and see?

> so <root> elements is used not only as a root element but inside the
> document as well.


Yes, provided the document is well-formed this is OK, if unusual.

> Is this a valid (in the wide sense) markup?


Only if you have a Schema or DTD to provide validation criteria, eg:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
<!ELEMENT root (element|root)+>
<!ELEMENT element (#PCDATA)>
]>
<root>
<element>Content</element>
<root><element>Content</element></root>
<element>Content</element>
</root>

However, except in specialist circumstances it's probably not good
design. Element type names are usually chosen to reflect some kind
of meaning, and it's hard to understand why you would want an
element type used both for the root element and for a descendant.

The closest analogy I can think of immediately is in the TEI, where
the second-level element <text> can be reused within a paragraph
(for example) when you are quoting an embedded document, like in a
story where someone reads or quotes a letter:

<TEI.2>
<teiHeader>
...etc...
</teiHeader>
<text>
<body>
<p>This is what he sent me:<text>
<body>
<salute>Dear Peter,</salute>
<p>...</p>
</body>
</text></p>
</body>
</text>
</tei.2>

That's not the root element, but I can't offhand think of anything
else doing this on a regular basis.

///Peter
--
XML FAQ: http://xml.silmaril.ie
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      10-29-2006
> However, except in specialist circumstances it's probably not good
> design. Element type names are usually chosen to reflect some kind
> of meaning, and it's hard to understand why you would want an
> element type used both for the root element and for a descendant.


That is not about my XML markup - with all defaults I have I still
normally do not do things like that
As other respondent properly guessed that was about the current SVG1.1
DTD on W3C. I just made my question fully abstract to avoid an
"authority pressure".
I'm glad to see that at least one person is sharing my surprise
feelings. As I nowhere to be a XML specs guru, I wanted to compare my
natural (yet non-academical) reaction with someone else's.

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      10-30-2006
Peter Flynn wrote:
> However, except in specialist circumstances it's probably not good
> design. Element type names are usually chosen to reflect some kind
> of meaning, and it's hard to understand why you would want an
> element type used both for the root element and for a descendant.


Some data structures are conceptually recursive, which would yield
exactly this kind of structure. One obvious example is a departmental
tree, where a manager may manage other managers in addition to
non-management employees.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      10-30-2006
Joseph Kesselman wrote:
> Some data structures are conceptually recursive, which would yield
> exactly this kind of structure. One obvious example is a

departmental
> tree, where a manager may manage other managers in addition to
> non-management employees.


IMHO a management tree is a strictly hierachical structure (as any
power chain in this matter). There is no "manager" as such unless as a
dictionary entry. There is store manager (one), assistant manager (each
time one on duty) and department managers (by the number of
departments).

<store_manager>
<assistant_manager>
<department_manager>
<working_bee>
</department_manager>
<department_manager>
<working_bee>
</department_manager>
</assistant_manager>
</store_manager>

that can be represented over attributes of course:

<manager type="store">
<manager type="assistant">
<manager type="department">
<working_bee>
</manager>
<manager type="department">
<working_bee>
</manager>
</manager>
</manager>

but it's lesser convenient (IMHO of course) as a data structure - and
still no recursion.

The question is than if SVG is conceptually recursive and
<svg>
<svg>
</svg>
</svg>
is the only way to solve it?

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      10-30-2006
VK wrote:
> IMHO a management tree is a strictly hierachical structure


Depends on what you're doing with it. My point was just that recursive
data structures are not uncommon in programming, so we shouldn't be
surprised to see them used, and supported, in XML-based languages.

> The question is than if SVG is conceptually recursive


I haven't looked at the SVG formal spec, so I don't know. My uninformed
guess would be that that while the top-level <svg/> element itself may
not happen to recur, other data structures within that language probably do.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      10-31-2006
Joseph Kesselman wrote:
> My point was just that recursive data structures are not uncommon
> in programming, so we shouldn't be surprised to see them used,
> and supported, in XML-based languages.


Your point is taken.

> > The question is than if SVG is conceptually recursive


> I haven't looked at the SVG formal spec, so I don't know. My uninformed
> guess would be that that while the top-level <svg/> element itself may
> not happen to recur, other data structures within that language probably do.


I may humbly ask everyone then to take a look at:
<http://www.w3.org/TR/SVG11/struct.html>
and
<http://www.w3.org/TR/SVG11/struct.html#SVGElement>

Poorly and briefly (at the best of my capabilities): each <svg>
(Scalable Vector Graphics) element defines an eternal geometrical
Decart space and a physically finit viewport ("window to the eternity")
to that space. In the currently proposed schema only the top level
<svg> may define the viewport, but any nested <svg> elements have their
viewports disregarded, they only have the right to map themselves to a
coords point in the Decart space of the outermost <svg>. This way I see
a XML structure where elements and their attributes are not treated by
DTD but by the node position in the tree.

Taking out the technical details, from purely structural positions:
would it be normal to give a special value to the node position of an
element in the tree (besides the element's rule in DTD). Or is it a
case of a recursive structure?

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      10-31-2006
VK wrote:
> Taking out the technical details, from purely structural positions:
> would it be normal to give a special value to the node position of an
> element in the tree (besides the element's rule in DTD). Or is it a
> case of a recursive structure?


"Normal" depends on the semantics of the XML-based language being
defined. For some applications it makes sense, for others it doesn't.

I'd call this one a case of recursive structure, defining the semantics
of embedding an SVG graphic within a larger SVG. Given the intent, it
makes perfect sense to me that the viewport is defined for the entire
image rather than for the contained fragment. But it's up to the
language's designers to make that decision.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie help- Can multiple instances with multiple namesautomatically created. Nav Python 15 01-05-2010 06:03 AM
Can Groovy be used in an applet and/or can it generate the Java bytecodes that then can be used in an applet? Casey Hawthorne Java 1 03-18-2009 12:56 AM
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM



Advertisments