在 XML 文档中包含带有查询字符串的 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8215348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Including a URL with query string in an XML document
提问by Steven
So I have this XML doc:
所以我有这个 XML 文档:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Item>
<URL>http://www.mysite.com/page?id=1</URL>
</Item>
</Root>
When I try and view the document, I get an error saying:
当我尝试查看文档时,我收到一条错误消息:
XML Parsing Error: not well-formed
XML 解析错误:格式不正确
at the =sign in the query string. I tried changing the =sign to %3D, but I get the same error at %
在=查询字符串中的符号处。我尝试将=符号更改为%3D,但在%
What am I supposed to do here?
我应该在这里做什么?
回答by Vincent Biragnet
As you provide it, the XML is well formed. You don't have anything to escape in it. Maybe you have encoding problems in your source file. For information, the 2 characters you must escape in XML are :
当您提供它时,XML 格式良好。你没有什么可以逃避的。也许您的源文件中存在编码问题。有关信息,您必须在 XML 中转义的 2 个字符是:
& in &
< in <
Characters you may escape in attributes values (depending on the syntax you use for attributes : attr='value'or attr="value") :
您可以在属性值中转义的字符(取决于您用于属性的语法 :attr='value'或attr="value"):
" in "
' in '
Depending on the context, the last character that can be escaped :
根据上下文,可以转义的最后一个字符:
> in >
回答by Himanshu A Jadav
You can try <URL><![CDATA[http://www.example.com/page?id=1]]></URL>
你可以试试 <URL><![CDATA[http://www.example.com/page?id=1]]></URL>
All text in an XML document will be parsed by the parser.
But text inside a CDATAsection will be ignored by the parser. You can find more here.
回答by mgraph
try this <URL><![CDATA[http://www.mysite.com/page?id=1]]></URL>
尝试这个 <URL><![CDATA[http://www.mysite.com/page?id=1]]></URL>

