Action #804
Verify XML logic
Status: | Closed | Start date: | 03/16/2013 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assigned To: | Knödlseder Jürgen | % Done: | 100% | |
Category: | - | |||
Target version: | 1.0.0 | |||
Duration: |
Description
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.
Recurrence
No recurrence.
History
#1 Updated by Knödlseder Jürgen almost 12 years ago
- Description updated (diff)
#2 Updated by Knödlseder Jürgen about 10 years ago
- Target version set to 1.0.0
Should be clarified for release version 1.0.0
#3 Updated by Knödlseder Jürgen almost 10 years ago
The following code
produces the following XML document
Two observations:
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>
Two observations:
- appending subsequent text nodes to a given XML element adds text fields to the element; they are represented in memory by multiple
GXmlText
objects; 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 10 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"))
#5 Updated by Knödlseder Jürgen almost 10 years ago
- % Done changed from 50 to 90
Forbid now also to append to comment and processing instruction node. I think I got now all the issues.
#6 Updated by Knödlseder Jürgen almost 10 years ago
- Status changed from In Progress to Closed
- % Done changed from 90 to 100
- Remaining (hours) set to 0.0
Merged into devel