- Robustness. A solution within the family should be most robust.
- There are extensions like EXSLT.
- Simplicity. Make it simple, as simple as possible, but no simpler.
- Last but not least, minimalism.
XML and the importance of proper encoding and document declaration
When working with documents containing language specific-data or when working with internatinalization and XML, you must deal with encoding properly.
Example, if you are from France and use French character set, you may get an error like this if you do not use proper encoding:
"Input is not proper UTF-8, ..."
if you use the libxml2.
The following declaration at the start of the document may fix the error:
<?xml version="1.0" encoding="ISO-8859-1"?>
There is also another aspect when usning libxml2, internal storage of an XML document. Regardless of the encoding specified for a document, the encoding is stored internally within libxml2 in UTF-8 format. Knowing this may save you hours of boring work, trying to fix an error.
Fortunately there are two extensions, iconv or mbstring that you should use when performing encoding conversion
The XSL document function.
Code: Select all
Generally you use this
axis::node test [predicats]
structure while filtering node sets. So you need to know the following concepts to perform tests:
- node test (name test / node type test)
- Predicates that filters the node set.
/*/NodeName1/NodeName2/[position() >= 1 and position() <= 3]
Example of a more advanced filtering based on attributes and an XPath function:
/*/*[local-name()="MyAttribute"]/*/*[position() >= 1 and position() <= 3]
By combining XPath, XPointer and XInclude, it should also be possible to filter fragments of external documents that can be embedded into your own documents without using any external script or programming language.
Example: You have an external file external.xml with the following structure:
You can then access myelement2 with the myID id in external.xml like this:
<xi:include href="external.xml" parse "xml" xpointer="xpointer(id('myID'))"/>
Broken link or external server down ...
My personal priority of learning XML.
- XML tagging.
- XPointer and XInclude.
- Name spaces in XML.
- XSL(T) and XSL-FO
- XML Schema
- Other XML technologies
Conclusion and advice:
If you find a simple solution within the XML member family, use that before you use a scripting / programming solution.
One advantage with external streaming parsers, is that the memory usage is much lesser than for tree based parsers that operate on the node tree in memory. So if memory usage is critical, that is an argument for using stream based parsers like SAX XML or XMLReader.