I was a bit surprised that using double slash as comments seems to be valid XML.
The following parses correctly with Python and xml.etree.ElementTree
and under xmllint --format
:
<root>
<child1>text1</child1>
<child2></child2> //this is a valid comment
<child3></child3>
</root>
I first thought that this could be seen as text node for root element, but trying it on python3 proved me wrong:
>>> import xml.etree.ElementTree as ET
>>> r=ET.parse("test.xml").getroot()
>>> r.text
'\n '
>>> child2=r[1]
>>> child2.text
>>> ET.tostring(child2)
b'<child2 /> //this is a valid comment\n '
Can someone point me to the spec where this is allowed ?