开发者

XML encoding safe?

开发者 https://www.devze.com 2023-01-22 15:56 出处:网络
I am creating xml file with my own tags and given values and that in form of String and again I decode that in XML.I have been said to

I am creating xml file with my own tags and given values and that in form of String and again I decode that in XML.

I have been said to check that is code-decode XML is XML encoding safe.

Any idea how to check it? or any th开发者_运维技巧ing that make it sure that it is XML safe.


If you would want to write </mytag> as the content between <mytag> and </mytag>, you have to escape the less-than and greater-than characters, for example. There are several entities defined for escaping:

&   -> &amp;
<   -> &lt;
>   -> &gt;
"   -> &quot;
'   -> &apos;

What programming language/platform are you using? If you aren't writing the XML all by yourself, there should be ways that you don't have to worry about this!


An XML document that satisfies XML spec is said to be "well-formed," whereas a document that satisfies a schema (such as XHTML) is said to be valid. Since you're rolling your own XML-derived language, you likely want to check well-formedness. If you Google "well-formedness checker," you'd find them online. Any XML parser also could be used to check it.

The basic idea is like @Philipp is saying, you can't use certain characters between the tags (like <), all begin tags need to match up with end tags, and Unicode characters are properly encoded.

0

精彩评论

暂无评论...
验证码 换一张
取 消