XML- Explanation
-
Good Day,
I want to understand the following methods in XML handlers:
startDocument(): How does this method work? Does it look for the first "<" element or any text?
endDocument(): How does it know the document has ended?
startElement(): Again how does it know the element has started
endElement(): How does it know it is the end element?
Thanks
-
Hi,
I haven't used the handlers you posted, but here is what I know about QXmlStreamReader. I believe the detection mechanism is similar:
All tokens are detected when the '>' character is found.
- StartDocument is detected at the '>' of the XML declaraion.
- StartElement is detected at the '>' of an element start tag.
- EndElement is detected at the '>' of an element end tag.
- EndDocument is detected at the '>' of the end tag of your top-level element.
Using the following document as an example:
@
<?xml version="1.0" encoding="UTF-8"?>
<Reply category="INIT">
<InitClusters>
<Cluster id="A" x="0" y="0"/>
<Cluster id="B" x="2" y="2"/>
</InitClusters>
</Reply>
@- <?xml version="1.0" encoding="UTF-8"?> -- StartDocument
- <Reply category="INIT"> -- StartElement
- <InitClusters> -- StartElement
- <Cluster id="A" x="0" y="0"/> -- StartElement and EndElement
- <Cluster id="B" x="2" y="2"/> -- StartElement and EndElement
- </InitClusters> -- EndElement
- </Reply> -- EndElement and EndDocument
-
Thanks for the reply.
Can we say that <something> is a start element ?
and
</something> is an end element?
Is my understanding correct?
The reader/handler knows it has reached the end of the document because it has previous read <Reply category="INIT"> and then it has found the </Reply> element.
Is my understanding correct?
Thank you for the help.
-
You're welcome.
[quote author="Paawan" date="1410075609"]Can we say that <something> is a start element ?
and
</something> is an end element?
Is my understanding correct?[/quote]Correct.
Also, <something/> is a small element that starts and ends at the same time.
[quote author="Paawan" date="1410075609"]The reader/handler knows it has reached the end of the document because it has previous read <Reply category="INIT"> and then it has found the </Reply> element.
Is my understanding correct?[/quote]Correct.
-
There has been a sample XML file that was given with the book.
@
<section id="xmlintro">
<title> Intro to XML </title>
<p> This is a paragraph </p>
<ul>
<li> This is an unordered list item. </li>
<li c="textbook"> This only shows up in the textbook </li>
</ul><p> The code example below shows how slacker processes includes: </p> <include src="testhello.cpp" mode="cpp"/>
<p> And here is another paragraph </p>
</section>@
In this file the xml version part is not given. How will the reader know that document is starting? By this I mean where is the StartDocument part in this file?
Thanks