Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/02/2015, 21:37
germangutierrez
 
Fecha de Ingreso: enero-2015
Mensajes: 43
Antigüedad: 9 años, 3 meses
Puntos: 3
Respuesta: Lectura de un XML (XDM) con PHP

si probas con xpath ?

http://codepad.org/Z9VIH0f6

Código PHP:
Ver original
  1. <?php
  2.  
  3. $XML_STR = <<<EOL
  4. <xdm:Device xmlns:xdm="http://www.hp.com/schemas/imaging/con/xdm/1.1/" xmlns:dd="http://www.hp.com/schemas/imaging/con/dictionaries/1.0/" xmlns:bsi="http://www.hp.com/schemas/imaging/con/bsi/2003/08/21" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:count="http://www.hp.com/schemas/imaging/con/counter/2006/01/13" xmlns:media="http://www.hp.com/schemas/imaging/con/media/2006/01/13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pwg="http://www.hp.com/schemas/imaging/con/pwg/sm/1.0/">
  5.     <xdm:Information>
  6.         <xdm:Component id="iSystem" componentType="system">
  7.             <dd:MakeAndModel>HP Color LaserJet CM6030 MFP</dd:MakeAndModel>
  8.             <dd:Description>BUSINESS 505549 E4 P2</dd:Description>
  9.             <dd:ProductNumber>CEXXX</dd:ProductNumber>
  10.             <dd:Manufacturer>
  11.                 <dd:Name>HP</dd:Name>
  12.             </dd:Manufacturer>
  13.             <dd:SerialNumber>ETETCD4744</dd:SerialNumber>
  14.             <dd:ServiceID>22013</dd:ServiceID>
  15.             <dd:Version>
  16.             <dd:Revision>52.132.6</dd:Revision>
  17.                 <dd:Date>2011-02-15</dd:Date>
  18.             </dd:Version>
  19.             <dd:MopierFunctionSetting>Enhanced</dd:MopierFunctionSetting>
  20.             <dd:AutomaticResourceSaving>Automatic Resource Saving Enabled</dd:AutomaticResourceSaving>
  21.         </xdm:Component>
  22.         <xdm:Component id="iMarkingEngineController" componentType="board">
  23.             <dd:BoardTypeEnum>markingEngineControl</dd:BoardTypeEnum>
  24.             <dd:Description>marking engine controller</dd:Description>
  25.             <dd:Version>
  26.                 <dd:Revision>PKauai 54</dd:Revision>
  27.             </dd:Version>
  28.         </xdm:Component>
  29.         <xdm:Component id="iFormatter" componentType="board">
  30.             <dd:BoardTypeEnum>systemControl</dd:BoardTypeEnum>
  31.             <dd:Description>formatter</dd:Description>
  32.         </xdm:Component>
  33.             </xdm:Information>
  34.             </xdm:Device>
  35.  
  36. EOL;
  37.  
  38. //$xml = simplexml_load_file("test.xml");
  39.  
  40. $xml = simplexml_load_string($XML_STR);
  41.  
  42. $results = $xml->xpath("/xdm:Device/xdm:Information/xdm:Component[1]/dd:MakeAndModel");
  43.  
  44. foreach ($results as $result) echo "$result\n";