我有this kind of xml文档。
我的问题是我不能通过simplexml读取标签,因为不同的名称空间。示例BuyerCustomerParty->Party->Person->FamilyName标记。BuyerCustomerParty、Party和Person在cac-namespace下,但FamilyName在cbc-namespace下。奇怪的是,我可以写入标签并替换内容,但不能在此之前读取它。
这里还有一些代码:
$sxe = simplexml_load_string($value);
$namespaces = $sxe->getDocNamespaces();
$sxe->registerXPathNamespace('cbc', $namespaces['cbc']);
$cbc = $sxe->children($namespaces['cbc']);
//THIS PRINTS THE RIGHT VALUE
$cbc->IssueDate;
$sxe->registerXPathNamespace('cac', $namespaces['cac']);
$cac = $sxe->children($namespaces['cac']);
//BUT THIS PRINTS NOTHING
echo $fg = $cac->BuyerCustomerParty->Party->Person->FamilyName;
//BUT IF I CHANGE THE VALUE OF THE TAG... I CAN ACCESS THE TAG
$cac->BuyerCustomerParty->Party->Person->FamilyName = "value";如何读取标签?
发布于 2016-07-14 15:24:35
我的解决方案是将cbc子代包含在路径中。
echo $fg = $cac->BuyerCustomerParty->Party->Person->children('cbc',TRUE)->FamilyName;https://stackoverflow.com/questions/21765994
复制相似问题