Jump to content
Sign in to follow this  
John Adriaan

Multiple XML Nodes of the same Type

Recommended Posts

According to the "Node Types" table on this W3Schools page, only the Document Node has a limit to the number of child Nodes (other than None!) of any one type:

Quote

"Element (max. one)"

The implication is that there can be any number of any other (listed) Child node in a Parent Node.

  • For many Nodes, that's a natural state:
    An Element Node can have many other Child Element Nodes to define the complete Tree.
  • For some Nodes, it's a little less natural:
    For example, one might think that a Comment Node is commenting on its Parent Node. Nope!
    A Comment Node is merely a child of its Parent, and is likely commenting on the following (or preceding!) Sibling Node - not the Parent Node.
  • But there are some Nodes where it's not obvious how multiple Child Nodes of the same Type should be represented.

Take, for example, the Element Node. It allows - in fact needs - a Text Node as a Child Node to store the actual text of Leaf Elements.

One could say that in a typical XML document, all Element Nodes have:

  • either zero (for empty Elements), one, or multiple Child Element Nodes;
  • or exactly one Child Text Node.

But this isn't (apparently) stipulated in the standard - hence this post.

  1. If a Child list has Child Text Nodes interspersed amongst Child Element Nodes, do they just get represented like that?
    <Parent>
      This is the first piece of text from the first Text Node.
      <Child1>
        ...
      </Child1>
      <Child2>
        ...
      </Child2>
      This is the second piece of text from the second Text Node.
      <Child3>
        ...
      </Child3>
    </Parent>

     

  2. How does are multiple Child Text Nodes represented?

    A simple concatenation of all the Texts? In the given order?

    <Parent>
      This is the first piece of text from the first Text Node. This is the second piece of text from the second Text Node.
    </Parent>
  3. How does one represent Child Text Nodes of Attr Nodes, as described/permitted in the above Node Types Table?

     

     

     

     

And I've not even considered EntityReference Nodes yet - which are also explicitly described as legal Child Nodes of Attr Nodes. (How?)

Share this post


Link to post
Share on other sites

I ran these through the JavaScript XML parser, to see if I could reveal the nature of the nodes. Worked well.

On 3/29/2019 at 12:18 AM, John Adriaan said:

If a Child list has Child Text Nodes interspersed amongst Child Element Nodes, do they just get represented like that?

#text
Child1
Child2
#text
Child3

 

On 3/29/2019 at 12:18 AM, John Adriaan said:

How does are multiple Child Text Nodes represented?

#text

The example noted has them together, so there is no separation, and they are concatenated as if it was one.

On 3/29/2019 at 12:18 AM, John Adriaan said:

How does one represent Child Text Nodes of Attr Nodes, as described/permitted in the above Node Types Table?

This part of that node page seems a little outdated. Attr Nodes aren't specifically... 'nodes' when processed (by JavaScript at least, but I don't know what other things there would be.)

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...