Verify XML logic
|Assigned To:||Knödlseder Jürgen||% Done:|
I guess that a XML element can either contain another element or a single text node. I’m not sure that the actual implementation respects this logic. It is likely that the actual implementation allows several text nodes within a given element, or even a mix of text nodes and other nodes. This should be checked and the required constraints should be implemented.
#3 Updated by Knödlseder Jürgen almost 8 years ago
xml = gammalib.GXml() level1 = xml.append('element type="Measurement"') level2 = level1.append('parameter name="Flux" value="1.0"') level3 = level2.append(gammalib.GXmlText("This is a text")) dump = level2.append(gammalib.GXmlText("This is another text")) dump = level2.append(gammalib.GXmlText("This is a third text")) level4 = level3.append(gammalib.GXmlText("This is a nested text")) level4 = level4.append(gammalib.GXmlText("This is a nested text"))
produces the following XML document
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <element type="Measurement"> <parameter name="Flux" value="1.0"> This is a text This is another text This is a third text </parameter> </element>
- appending subsequent text nodes to a given XML element adds text fields to the element; they are represented in memory by multiple
GXmlTextobjects; this was maybe not intended but does not really present a problem
- appending a text node to a text node does nothing; it’s like the appended text node got lost; this is not a nice feature; probably an exception should be thrown.
#4 Updated by Knödlseder Jürgen almost 8 years ago
- Status changed from New to In Progress
- Assigned To set to Knödlseder Jürgen
- % Done changed from 0 to 50
I added some code to
GXmlNode that throws an exception if an attempt is made to append anything to a text node. This now leads to
Traceback (most recent call last): File "./test_xml.py", line 90, in <module> xml = test1() File "./test_xml.py", line 47, in test1 level4 = level3.append(gammalib.GXmlText("This is a nested text")) File "/usr/local/gamma/lib/python2.6/site-packages/gammalib/xml.py", line 330, in append return _xml.GXmlNode_append(self, *args) RuntimeError: *** ERROR in GXmlNode::append(GXmlNode&): Invalid value. Invalid attempt to append a XML node to a text node (GXmlText). Nothing can be appended to a text node.
for the above code, hence an exception for
level4 = level3.append(gammalib.GXmlText("This is a nested text"))