简体   繁体   English

如何通过libxml2获取包含“&”的正确属性

[英]How to get right attribute which contain “&” through libxml2

When I try to get the attribute of URL in a test XML: 当我尝试在测试XML中获取URL的属性时:

<Test> <Item URL="http://127.0.0.1?a=1&b=2"/>
</Test>

After I call: attr=xmlGetProp(cur, BAD_CAST "URL"); 我打电话后:attr = xmlGetProp(cur,BAD_CAST“URL”);

The libxml2 give a message: Entity: line 1: parser error : EntityRef: expecting ';' libxml2给出一条消息:实体:第1行:解析器错误:EntityRef:expecting';'

and return value of attr is "http://127.0.0.1?a=1=2" 并且attr的返回值是“http://127.0.0.1?a=1=2”

How can I get the completion attribution of URL? 如何获取URL的完成归属? Thanks 谢谢

You cannot get the “correct” URL here because the XML file is not well-formed . 你不能在这里得到了“正确的” URL,因为没有很好地形成的XML文件。 the & should have been written as &amp; &应该写成&amp; . You have to ask the creator of the XML file to create a syntactically valid, well-formed XML file . 您必须要求XML文件的创建者创建一个语法上有效,格式良好的XML文件

XML is not created by just putting strings together, they also have to be encoded properly. 只是将字符串放在一起就不会创建XML,它们也必须正确编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM