TiXI
3.3.0
|
These functions are used, to register xml namespaces to the parser or add namespaces to existing elements. For the following explanations, consider the following xml file. More...
These functions are used, to register xml namespaces to the parser or add namespaces to existing elements. For the following explanations, consider the following xml file.
<root> <h:table xmlns:h="http://www.w3.org/TR/html4/"> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <aircraft xmlns="http://www.dlr.de/cpacs"> <modelname>D150</modelname> </aircraft> </root>
This file defines two namespaces - "http://www.w3.org/TR/html4/" and "http://www.dlr.de/cpacs". A query for "/root/h:table" or "/root/aircraft" will result in an error, as no prefix was defined for both namespaces. The prefix inside the xml file exists only in the file, but not in the parser. To successfully query these paths, the namespaces must be registered with some (arbitrary) prefix using tixiRegisterNamespace or tixiRegisterNamespacesFromDocument.
After calling tixiRegisterNamespace(handle, "http://www.w3.org/TR/html4/", "html") the query for "/root/html:table" is now valid. After calling tixiRegisterNamespace(handle, "http://www.dlr.de/cpacs", "cpacs") the query for "/root/cpacs:aircraft" becomes valid.
To write elements with namespaces, the following functions are available:
To reproduce the upper xml file, use the following tixi code:
tixiCreateDocument("root", &handle); // create table element in prefixed html namespace tixiCreateElementNS(handle, "/root", "h:table", "http://www.w3.org/TR/html4/"); tixiRegisterNamespace(handle, "http://www.w3.org/TR/html4/", "h"); tixiCreateElementNS(handle, "/root/h:table", "tr", "http://www.w3.org/TR/html4/"); tixiAddTextElementNS(handle, "/root/h:table/h:tr", "td", "http://www.w3.org/TR/html4/", "Apples"); tixiAddTextElementNS(handle, "/root/h:table/h:tr", "td", "http://www.w3.org/TR/html4/", "Bananas"): // create aircraft in default namespace (no prefix!) tixiCreateElementNS(handle, "/root", "aircraft", "http://www.dlr.de/cpacs"); tixiRegisterNamespace(handle, "http://www.dlr.de/cpacs", "c"); tixiAddTextElementNS(handle, "/root/c:aircraft", "modelname", "http://www.dlr.de/cpacs", "D150");