Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Obtener el valor del campo XML que coincide con una propiedad a través de XPATH

Tengo un esquema XML realmente extraño que me está causando un dolor y un dolor innecesarios.

Necesito obtener el valor de un nodo IMAGEFILENAME que tiene la propiedad "ocultar".

El esquema XML se parece a:

 <PHOTOS> <IMAGETHUMBFILENAME/> <IMAGECAPTION> This is a caption </IMAGECAPTION> <PRINTQUALITYIMAGE> /mylocation/filename1.jpg </PRINTQUALITYIMAGE> <IMAGEFILENAME pictype="show"> /mylocation/filename2.jpg </IMAGEFILENAME> <IMAGETHUMBFILENAME/> <IMAGECAPTION>This is another caption</IMAGECAPTION> <PRINTQUALITYIMAGE> /mylocation/filename3.jpg </PRINTQUALITYIMAGE> <IMAGEFILENAME pictype="hide"> /mylocation/filename4.jpg </IMAGEFILENAME> <IMAGETHUMBFILENAME/> </PHOTOS>

Y me las arreglé para llegar a la siguiente XPATH usando PHP:

 $nodes = $xml->xpath('/PHOTOS/IMAGEFILENAME[@pictype="hide"]'); var_dump($nodes);

Cuando hago un volcado de $nodes var, lo que espero ver (y lo que quiero) es obtener el valor /mylocation/filename4.jpg . En cambio, lo que obtengo es:

 array(1) { [0]=> object(SimpleXMLElement)#333 (1) { ["@attributes"]=> array(1) { ["pictype"]=> string(10) "hide" } } }

Probé varias combinaciones de /parent , /text() y /node() pero sin alegría alguna.

Por favor, que alguien me diga lo marioneta que estoy siendo y sáqueme de mi miseria. ¿Es eso o el esquema es problemático?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Entonces, tienes una matriz de SimpleXMLElements.

Para obtener una representación de cadena de SimpleXMLElement , simplemente puede echo :

 $nodes = $xml->xpath('/PHOTOS/IMAGEFILENAME[@pictype="hide"]'); echo $nodes[0]; // I used `[]` notation to get first element of array

Para usar la representación de cadena de SimpleXMLElement más adelante en su código, puede convertirlo en cadena explícitamente:

 $nodes = $xml->xpath('/PHOTOS/IMAGEFILENAME[@pictype="hide"]'); $node_str = strval($nodes[0]); // still `[]` notation
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!