2010-11-04 6 views
0

Salutations,Quel est l'objectif de point-virgule (;) en XmlAttribute :: AttributeName (DotNet)

Je suis en train de résoudre un mystère de programmation (pour moi). J'ai cherché des lunettes, mais je n'ai rien trouvé sur l'utilisation du point-virgule dans la propriété AttributeName de XmlAttribute. Je travaille avec une application qui sérialise un objet. Lorsque cet objet est sérialisé, tous les attributs ont la même valeur qu'un suffixe.

Par exemple:

[XmlType(TypeName = "Foo", Namespace = Declarations.SchemaVersion), XmlRoot, Serializable] 
public class Foo 
{ 
    private string _Name; 

    [XmlAttribute(AttributeName = "Name;", Form = XmlSchemaForm.Unqualified, DataType = "string", Namespace = Declarations.SchemaVersion)] 
    public string Name 
    { 
     get 
     { 
      return this._Name; 
     } 
     set 
     { 
      this._Name = value; 
     } 
    } 
} 

Get sérialiser comme:

<Foo Name_x003B_="John" /> 

Ma question est, où est-ce x003B est venu de (j'ai cherché le code pour un littéral "x003B "mais n'a rien trouvé {ce qui précède est juste un exemple, je travaille avec un grand code de base}). Où puis-je le changer? Quel est le but du point-virgule à la fin de AttributeName? Merci!

Répondre

2

XmlSerializer code des caractères tels que des points-virgules en le plaçant dans underscores avec la valeur hexadécimale du caractère intérieur pour Prénom; devient Name_0x003B_. Si vous mettez un point d'interrogation dans ce champ, ce sera Name_0x003F_.

0

-t-il pas venu de

AttributeName = "Name;" 
2

C'est la valeur codée de ; = _x003B_

1

Je suis surpris qu'il soit autorisé en tant que caractère unique dans un nom d'attribut XML. XML ne permet pas:

<Foo Name;="bar"/> 

SPEC:

The first character of a Name MUST be a NameStartChar, and any other characters MUST be NameChars; this mechanism is used to prevent names from beginning with European (ASCII) digits or with basic combining characters. Almost all characters are permitted in names, except those which either are or reasonably could be used as delimiters. The intention is to be inclusive rather than exclusive, so that writing systems not yet encoded in Unicode can be used in XML names. See J Suggestions for XML Names for suggestions on the creation of names. 

Document authors are encouraged to use names which are meaningful words or combinations of words in natural languages, and to avoid symbolic or white space characters in names. Note that COLON, HYPHEN-MINUS, FULL STOP (period), LOW LINE (underscore), and MIDDLE DOT are explicitly permitted. 

The ASCII symbols and punctuation marks, along with a fairly large group of Unicode symbol characters, are excluded from names because they are more useful as delimiters in contexts where XML names are used outside XML documents; providing this group gives those contexts hard guarantees about what cannot be part of an XML name. The character #x037E, GREEK QUESTION MARK, is excluded because when normalized it becomes a semicolon, which could change the meaning of entity references. 
Names and Tokens 
[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] 
[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] 
[5] Name ::= NameStartChar (NameChar)* 
[6] Names ::= Name (#x20 Name)* 
[7] Nmtoken ::= (NameChar)+ 
[8] Nmtokens ::= Nmtoken (#x20 Nmtoken)* 

Ce qui semble arrivé est que le système a traduit le caractère interdit « ; » à un ensemble de caractères qui sont interprétables par les humains mais pas les machines à un point de code Unicode. Je ne pense pas que ce soit un comportement standard dans toutes les implémentations XML.

Je voudrais également soupçonner qu'il est susceptible d'être une erreur, car un nom d'attribut de "Nom"; est susceptible de causer des problèmes dans certains outils XML.

Questions connexes