0

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?

kero
  • 10,647
  • 5
  • 41
  • 51
  • `xpath` might help. see my answer here: http://stackoverflow.com/questions/21788253/simplexml-is-not-parsing-my-epp-xml-messages – michi Feb 15 '14 at 14:52
  • possible duplicate of [PHP namespace simplexml problems](http://stackoverflow.com/questions/2098170/php-namespace-simplexml-problems) – IMSoP Feb 15 '14 at 19:09

1 Answers1

1

my solution was to include the cbc children down the path.

echo $fg = $cac->BuyerCustomerParty->Party->Person->children('cbc',TRUE)->FamilyName;
Nijboer IT
  • 1,178
  • 1
  • 13
  • 18