Why am I getting an XmlException in valid XML?

In the process of testing a method that takes a string and adds this string as an XElement attribute (with the current time as a value). To use XElement.SetAttributeValue(XName name, object value) (the only way I know is to add / update the XElement attribute), I use XName.Get to convert the provided string to XName.

The problem I am facing is that XName.Get (the stack trace shows that it comes from System.Xml.XmlConvert.VerifyNCName ) throws an XmlException in some cases, requiring that certain characters are not allowed. One example is 0x02FF (˱). I would not expect this character to be allowed, but the XML specification seems to say that the entire range from 0x00F8 to 0x02FF is valid.

Am I getting this exception from valid characters, or am I misunderstanding the specification?

+4
source share
1 answer

The AFAIR Xml stack in the .NET Framework 4 and .NET Framework 4.5 is based on the fourth release of the Xml specification, not the fifth. When you look at this specification, you will notice that not all valid characters are allowed in names. Especially look at this and see that Letter is, and you will see that characters from the range [0x02C2-0x0385] are excluded.

Also, the reason the Xml stack in the .NET Framework 4 and 4.5 did not go to the fifth edition was because of changes in character ranges, the same Xml document may be valid or invalid (this is actually a problem which you click) depending on the processor, and not on the document itself (Xml documents that correspond to the fifth edition may still have version 1.0). Thus, valid documents (corresponding to the fifth edition) will be rejected by the senior parsers as invalid. It also didn't work the other way around. If an Xml processor compatible with the 5th edition received a document with a character in the name that was previously invalid but valid in the 5th edition, it was impossible to say whether this document should be rejected as the one that should have been before 5 The 2nd edition is incorrect, or it is the fifth edition document, and it should be adopted.

+3
source

All Articles