【发布时间】:2016-01-12 15:33:17
【问题描述】:
我正在尝试解码下面给出的一个肥皂 xml 数据包
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope>
<SOAP-ENV:Header><cwmp:ID SOAP-ENV:mustUnderstand="230">105</cwmp:ID>
</SOAP-ENV:Header>
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cwmp:Request>
<Id>100</Id>
<RequestEvent SOAP-ENC:arrayType="cwmp:RequestStruct[3]">
<RequestStruct>
<Code>0 ZERO</Code>
<Key></Key>
</RequestStruct>
<RequestStruct>
<Code>1 ONE</Code>
<Key></Key>
</RequestStruct>
<RequestStruct>
<Code>2 TRAP</Code>
<Key></Key>
</RequestStruct>
</RequestEvent>
</cwmp:Request>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
当我尝试使用代码解码数据包时
BOOST_FOREACH(boost::property_tree::ptree::value_type &SL_vTemp, pt.get_child("SOAP-ENV:Envelope.SOAP-ENV:Body.cwmp:Request.RequestEvent"))
{
struct param obj;
obj._Name.assign(SL_vTemp.second.get<std::string>("Code"));
obj._Value.assign(SL_vTemp.second.get<std::string>("Key"))
}
我收到异常,没有名为 EventCode 的节点。 但是,如果我要从soap xml 数据包中删除属性部分“SOAP-ENC:arrayType="cwmp:RequestStruct[3]”,那么代码工作正常。 提前致谢。
【问题讨论】:
-
Boost.Property-tree 不是 general XML parser。请停止这样对待它。
-
@NicolBolas 在这里,我收到了来自 CPE 的请求,该请求采用的是 soap xml 格式。因此,要获取soap xml 中存在的参数,我必须对数据包进行解码。对于那个解码部分,我正在使用 boost。我在问题中提供的示例肥皂 xml 数据包。如果您知道任何比 boost 更好的库,请告诉我。谢谢
-
@vanneilsen Nicol 说“不要使用 boost”。当然,我们知道一个更好的库。你也是:use the force。我用普吉。很好,只有标题。
-
感谢分享链接。