[xml] anyURI datatype won't accept an empty value



The XML Signature spec (http://www.w3.org/TR/xmldsig-core/) has an
example of an empty 'anyURI' attribute in a 'Reference' element:

 URI=""
    Identifies the node-set (minus any comment nodes) of the XML
    resource containing the signature

The "anyURI" datatype in libxml2 doesn't seem to support this kind of
empty value. Is it a bug in libxml2? Here is an example of the problem
using libml2 2.6.6 with the python bindings:

$ cat tmp.py
import libxml2

raw_schema = """<?xml version='1.0' encoding='UTF-8'?>
<element xmlns='http://relaxng.org/ns/structure/1.0'
         datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'
         name='URI'>
  <data type='anyURI'/>
</element>"""

raw_doc0 = """<?xml version='1.0' encoding='UTF-8'?>
<URI>http://bogus</URI>"""

raw_doc1 = """<?xml version='1.0' encoding='UTF-8'?>
<URI></URI>"""

def test():
  schema_xml = None
  doc0_xml = None
  doc1_xml = None
  try:
      schema_xml = libxml2.parseMemory(raw_schema, len(raw_schema))
      doc0_xml = libxml2.parseMemory(raw_doc0, len(raw_doc0))
      doc1_xml = libxml2.parseMemory(raw_doc1, len(raw_doc1))
      rngp = schema_xml.relaxNGNewDocParserCtxt()
      rngs = rngp.relaxNGParse()
      rctxt = rngs.relaxNGNewValidCtxt()
      print raw_doc0
      print
      print doc0_xml.relaxNGValidateDoc(rctxt)
      print
      print raw_doc1
      print
      print doc1_xml.relaxNGValidateDoc(rctxt)
      print
  finally:
      if doc0_xml: doc0_xml.freeDoc()
      if doc1_xml: doc1_xml.freeDoc()
      if schema_xml: schema_xml.freeDoc()

test()

$ python tmp.py
<?xml version='1.0' encoding='UTF-8'?>
<URI>http://bogus</URI>

0

<?xml version='1.0' encoding='UTF-8'?>
<URI></URI>

Type anyURI doesn't allow value ''
Error validating datatype anyURI
Element URI failed to validate content
1


PS: Any word on the status of python bindings for c14n?

--
Anthony Carrico



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]