[ fromfile: xmlparsing-questions.xml id: xmlparsing-questions ]
If there is a syntax error in your XML file, how do you determine the cause and location?
xmllint is one way. Also, you can define an ErrorHandler in SAX, or ask the QXmlStreamReader for the line number of errors. Also, XML editors such as jEdit with the XML plugin can parse and show you where errors in XML documents are.
SAX is an event-driven parser. What kinds of events does it respond to?
Start of element, end of element, characters, etc
Compare and contrast SAX and DOM. Why would you use one rather than the other?
SAX is a lower-level API, which handles individual parse events (start of element, end of elementm etc). DOM is an Object Model, which uses SAX under the covers to parse the data into an in-memory tree structure. SAX is useful if you need a way to quickly process infinitely large XML files in a stream-like way. DOM is nice if you want to load the entire tree into memory and traverse/manipulate it.
If you have a QDomNode and it is actually "pointing" to a QDomElement, how do you get a reference to the QDomElement?
You can't use normal typecasts because QDomNode and QDomElement are not pointers. Therefore, use the toElement()
function instead.
What are the advantages of using QXmlStreamReader over SAX?
It is faster, uses less memory, and is easier to learn and use.
What are the advantages of using QXmlStreamReader over DOM?
DOM needs to load an entire document in memory, using a very inefficient representation. With the QXmlStreamReader, you can choose to create or not create objects of any size you want as you are parsing the document.
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |