Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a XML element contain text and child elements at the same time?

I was looking at some xml files but didn't find the answer to my question: Can a XML element contain text and child elements at the same time?

For example:

<tree>     <node1>        textTextText        <subnode1> text1 </subnode1>       <subnode2> text2 </subnode2>     </node1> </tree> 

I always see these kinds:

    <node2>        <sub1> text </sub1>     </node2> 
like image 684
user1386966 Avatar asked Aug 26 '12 12:08

user1386966


People also ask

What is an XML child element?

An XML tree starts at a root element and branches from the root to child elements. All elements can have sub elements (child elements): <root> <child>

When to use element vs attribute XML?

If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data.

What are the elements in XML?

XML elements can be defined as building blocks of an XML. Elements can behave as containers to hold text, elements, attributes, media objects or all of these. Each XML document contains one or more elements, the scope of which are either delimited by start and end tags, or for empty elements, by an empty-element tag.

Can we have empty XML tags?

Empty XML ElementsAn element with no content is said to be empty. The two forms produce identical results in XML software (Readers, Parsers, Browsers). Empty elements can have attributes.


1 Answers

Yes. A parent node contains zero or more child nodes. Text nodes and element nodes are two kinds of nodes and an element node can have any number of text and/or element child nodes in any order. Schemas might restrict this, though. In fact, the whitespace between element nodes actually forms text node siblings. Usually this whitespace is ignored, though.

like image 191
John Watts Avatar answered Sep 20 '22 16:09

John Watts