Introduction 2. Character Data 2. Attributes 3. Comments 4. See Also. Leave a Reply Cancel reply Your email address will not be published. Next Next post: How do I check if a checkbox is checked in jQuery? The above answers including accepted one mention all five characters should be escaped inside attributes.
Do you have any reference to XML standard to back what you are saying as your answer logically seems to be the correct one? RomanSusi: Yes, many other answers contain errors or overgeneralizations "The safe way RomanSusi: The specific statement that "all five characters should be escaped inside attributes" is sloppy guidance unsupported by the official BNF rule for AttValue cited in my answer via a link on 2.
Attribute Values. Show 4 more comments. Escaping characters is different for tags and attributes. Peter Bartels Peter Bartels 1, 1 1 gold badge 10 10 silver badges 19 19 bronze badges. This implies that for attributes only quotes need to be escaped, but that is in addition to the other three characters — eug. Tim Cooper Tim Cooper 9, 5 5 gold badges 58 58 silver badges 70 70 bronze badges.
The accepted answer is not correct. Best is to use a library for escaping xml. As mentioned in this other question "Basically, the control characters and characters out of the Unicode ranges are not allowed. Gabriel Furstenheim Gabriel Furstenheim 2, 21 21 silver badges 20 20 bronze badges. Questionless Questionless 29 4 4 bronze badges. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete?
Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile. Linked See more linked questions. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.
Accept all cookies Customize settings. The greater than and less than characters do no have to be escaped but its good practice to do it. Data within a comment block can not be escaped. When the XML document is parsed Character references are not expanded , so any chars within a Comment block are just seen as character data. The sequence -- may not appear within a comment, no provision is provided for escaping this sequence.
Character references allow the character code to be specified within the data instead of the literal character.
0コメント