Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, just looking at your XML gives me a headache. Here are a few changes you need to make:</p> <ol> <li>If you are going to have multiple nodes, then you need a wrapper such as before all of the nodes and after all of them.</li> <li>Your PROP node needs a closing tag</li> <li>Your CDATA is misformatted, the proper format is </li> </ol> <p>Here's my example of the newly formatted XML:</p> <pre><code>&lt;?xml version='1.0'?&gt; &lt;RECORDS&gt; &lt;RECORD&gt; &lt;PROP NAME="Product"&gt; &lt;PVAL&gt;&lt;![CDATA[Produkt1]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;PROP NAME="Value"&gt; &lt;PVAL&gt;&lt;![CDATA[10]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;PROP NAME="Status"&gt; &lt;PVAL&gt;&lt;![CDATA[Active]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;/RECORD&gt; &lt;RECORD&gt; &lt;PROP NAME="Product"&gt; &lt;PVAL&gt;&lt;![CDATA[Produkt2]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;PROP NAME="Value"&gt; &lt;PVAL&gt;&lt;![CDATA[20]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;PROP NAME="Status"&gt; &lt;PVAL&gt;&lt;![CDATA[Active]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;/RECORD&gt; &lt;RECORD&gt; &lt;PROP NAME="Product"&gt; &lt;PVAL&gt;&lt;![CDATA[Produkt3]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;PROP NAME="Value"&gt; &lt;PVAL&gt;&lt;![CDATA[30]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;PROP NAME="Status"&gt; &lt;PVAL&gt;&lt;![CDATA[Active]]&gt;&lt;/PVAL&gt; &lt;/PROP&gt; &lt;/RECORD&gt; </code></pre> <p></p> <p>Once the XML is formatted properly, I'd use something like SimpleXML to parse it:</p> <pre><code>$xml = simplexml_load_string( $xml_string ); foreach ($xml-&gt;RECORD as $record) { if ($record-&gt;PROP[0]-&gt;PVAL == 'Produkt1') { echo json_encode( $record ); } } </code></pre> <p>I also think you could really benefit from restructuring the entire XML. Something like:</p> <pre><code>&lt;RECORDS&gt; &lt;RECORD ID="1"&gt; &lt;PRODUCT&gt;PRODUCT 1&lt;/PRODUCT&gt; &lt;VALUE&gt;10&lt;/VALUE&gt; &lt;STATUS&gt;Active&lt;/STATUS&gt; &lt;/RECORD&gt; &lt;RECORD ID="2"&gt; &lt;PRODUCT&gt;PRODUCT 2&lt;/PRODUCT&gt; &lt;VALUE&gt;20&lt;/VALUE&gt; &lt;STATUS&gt;Active&lt;/STATUS&gt; &lt;/RECORD&gt; &lt;RECORD ID="3"&gt; &lt;PRODUCT&gt;PRODUCT 3&lt;/PRODUCT&gt; &lt;VALUE&gt;30&lt;/VALUE&gt; &lt;STATUS&gt;Active&lt;/STATUS&gt; &lt;/RECORD&gt; &lt;/RECORDS&gt; </code></pre> <p>So then the PHP would be like:</p> <pre><code>foreach ($xml-&gt;RECORD as $record) { $attr = $record-&gt;attributes(); if( $attr['ID'] == '1' ) { echo json_encode( $record ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload