Saturday, 21 November 2015

XML : How to get attribute of node with namespace using SimpleXML PHP?

i'm trying to get the attribute info. of some fields. This is the xml.

  <cfdi:Receptor nombre="JOSE GARCIA" rfc="GAJO540225EZ3"><cfdi:Domicilio calle="Conocido San Cristobal Casa 1" codigoPostal="47503" colonia="Rancho San Cristobal" estado="Jalisco" municipio="Lagos de Moreno" noExterior="S/N" noInterior="N/A" pais="Mexico" />  

I'm trying get the values with this code (part of them), using the rules of the namespaces with simplexml, can anyone tell me how this works?

  $xml = simplexml_load_file("factura.xml") or die("ERROR: Cannot create SimpleXML object");  //print_r($xml);  // open MySQL connection  $connection = mysqli_connect("localhost", "root", "", "rbp") or die ("ERROR: Cannot connect");  // process node data  // create and execute INSERT queries  foreach ($xml->cfdi->ExpedidoEn as $Receptor) {  $atributos = $Receptor->attributes();  $rfc = $atributos->rfc; //y no $product->name  $nombre_rs = $atributos->nombre;  $calle = $atributos->calle;  

I see this error on php: Warning: Invalid argument supplied for foreach()

No comments:

Post a Comment