marvin-zhao / pyang

Automatically exported from code.google.com/p/pyang
0 stars 0 forks source link

attributes in YIN should be normalized #64

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Attribute values obtained from YIN are not normalized according to the XML 
rules (sec. 3.3.3 in XML spec).
For example, <min-elements value=" 2"/> (note the leading space) should be OK 
but pyang complains:

error: bad value " 2" (should be non-negative-integer)

Original issue reported on code.google.com by lada.lho...@gmail.com on 26 Jan 2012 at 2:29

GoogleCodeExporter commented 9 years ago
I am not sure this is a bug.  3.3.3 of the XML spec says:

  If the attribute type is not CDATA, then the XML processor MUST further process the
  normalized attribute value by discarding any leading and trailing space

  All attributes for which no declaration has been read SHOULD be treated by 
  non-validating processor as if declared CDATA.

So all these attributes are CDATA, and thus no whitespace stripping should take 
place.

(BTW, the yin parser relies on expat for the XML parsing)

/martin

Original comment by mbj4...@gmail.com on 26 Jan 2012 at 6:43

GoogleCodeExporter commented 9 years ago
It is really a tricky question. My reading is that the value is pyang is in 
fact a validating parser and requires the attribute value to be a non-negative 
integer rather that opaque character data (see the error message).

Of course, the text in the XML spec speaks in terms of a DTD, so you can always 
argue that as long as there is no DTD the attribute values should not be 
normalized. But then the text would be effectively useless because nobody cares 
about DTDs these days.

The practical issue, at least from my point of view, is that pyang differs from 
RELAX NG validators when validating e.g. <min-elements value=" 2"/> against the 
RNG schema in schema/yin.rng. I tried xmllint, jing and nxml-mode validator and 
all consider the value to be a valid nonNegativeInteger. However, validation 
against an equivalent XSD schema gives an error. Oh well. :-(

Lada

Original comment by lada.lho...@gmail.com on 27 Jan 2012 at 9:28

GoogleCodeExporter commented 9 years ago
Apart from the tricky XML normalization issues, pyang could perhaps be more 
liberal and allow leading and trailing whitespace in number in both YANG and 
YIN syntax, so that e.g.

min-elements " 1";

would be OK.

Lada

Original comment by lada.lho...@gmail.com on 8 Mar 2012 at 1:39