I have this kind of xml document.
My problem is that I cannot read the tags with by simplexml, because the different namespaces. Example BuyerCustomerParty->Party->Person->FamilyName
tag. BuyerCustomerParty
, Party
and Person
are under cac
-namespace, but the FamilyName
is under cbc
-namespace. Weird is that I can write to the tag and replace the content, but cannot read it before that.
Here some code also:
$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";
How can I read the tag?