Note that there are some explanatory texts on larger screens.

plurals
  1. POParse a xml attribute depending on child content
    primarykey
    data
    text
    <p>I load an external xml file containing user metas looking like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;user_information&gt; &lt;user url="http://usersweb.com"&gt; &lt;name&gt;Arnold&lt;/name&gt; &lt;lastname&gt; &lt;name&gt;Arnoldson&lt;/name&gt; &lt;/lastname&gt; &lt;age&gt;42&lt;/age&gt; &lt;/user&gt; &lt;user url="http://anotheruserweb.com"&gt; &lt;name&gt;Arnold&lt;/name&gt; &lt;lastname&gt; &lt;name&gt;Arichson&lt;/name&gt; &lt;/lastname&gt; &lt;age&gt;42&lt;/age&gt; &lt;/user&gt; And so on.... &lt;/user_information&gt; </code></pre> <p>I know the formatting with</p> <pre><code>&lt;lastname&gt; </code></pre> <p>is really stupid, but i can't modify the source.</p> <p>I want to load in the "url"-attribute from </p> <pre><code>&lt;user&gt; </code></pre> <p>, but only if </p> <pre><code>&lt;name&gt; </code></pre> <p>and </p> <pre><code>&lt;lastname&gt; </code></pre> <p>matches the name values i have stored in my own user database.</p> <p>I know how to parse the rest of it with PHP, but just the matching sequence seems difficult to me. Any help appreciated!</p> <hr> <p><strong>EDIT:</strong> Since i can not give you the source XML, i found a similar code structure in the Spotify Metadata API. We can laborate with the returning XML-file from the track search "Domino Dancing": <a href="http://ws.spotify.com/search/1/track?q=Domino%20Dancing" rel="nofollow" title="Spotify Metadata API">ws.spotify.com/search/1/track?q=Domino Dancing</a></p> <p>It has the exactly same structur, excepts it use other words. The returning file looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;tracks xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1"&gt; &lt;opensearch:Query role="request" startPage="1" searchTerms="Domino Dancing"/&gt; &lt;opensearch:totalResults&gt;39&lt;/opensearch:totalResults&gt; &lt;opensearch:startIndex&gt;0&lt;/opensearch:startIndex&gt; &lt;opensearch:itemsPerPage&gt;100&lt;/opensearch:itemsPerPage&gt; &lt;track href="spotify:track:2aV5vCNH5tOOe0GGKqfx5Z"&gt; &lt;name&gt;Domino dancing&lt;/name&gt; &lt;artist href="spotify:artist:2ycnb8Er79LoH2AsR5ldjh"&gt; &lt;name&gt;Pet Shop Boys&lt;/name&gt; &lt;/artist&gt; &lt;id type="isrc"&gt;GBAYE0301704&lt;/id&gt; &lt;album href="spotify:album:0BAfuhzkGjckMhsL2gVbzR"&gt; &lt;name&gt;Ultimate&lt;/name&gt; &lt;released&gt;2010&lt;/released&gt; &lt;availability&gt; &lt;territories&gt;AT BE CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU NL NO PL PT RO SE SI SK&lt;/territories&gt; &lt;/availability&gt; &lt;/album&gt; &lt;track-number&gt;7&lt;/track-number&gt; &lt;length&gt;258.106000&lt;/length&gt; &lt;popularity&gt;0.57092&lt;/popularity&gt; &lt;/track&gt; &lt;track href="spotify:track:4mVLzFbc3gaCoWCEENLouc"&gt; &lt;name&gt;Domino Dancing&lt;/name&gt; &lt;artist href="spotify:artist:2ycnb8Er79LoH2AsR5ldjh"&gt; &lt;name&gt;Pet Shop Boys&lt;/name&gt; &lt;/artist&gt; &lt;id type="isrc"&gt;GBAYE8800056&lt;/id&gt; &lt;album href="spotify:album:0Jt2LzWgtGxy3GZH5i2Kcy"&gt; &lt;name&gt;Discography - Complete Singles Collection&lt;/name&gt; &lt;released&gt;1991&lt;/released&gt; &lt;availability&gt; &lt;territories&gt;AT BE CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU NL NO PL PT RO SE SI SK&lt;/territories&gt; &lt;/availability&gt; &lt;/album&gt; &lt;track-number&gt;10&lt;/track-number&gt; &lt;length&gt;258.333000&lt;/length&gt; &lt;popularity&gt;0.56159&lt;/popularity&gt; &lt;/track&gt; &lt;track href="spotify:track:72kgJ1brMxxeDiPNdH6qqW"&gt; &lt;name&gt;Viva la vida/Domino dancing&lt;/name&gt; &lt;artist href="spotify:artist:2ycnb8Er79LoH2AsR5ldjh"&gt; &lt;name&gt;Pet Shop Boys&lt;/name&gt; &lt;/artist&gt; &lt;id type="isrc"&gt;GBCEW0900049&lt;/id&gt; &lt;album href="spotify:album:4DZfMTDyBwnJQ0k1PaT6U4"&gt; &lt;name&gt;Pet Shop Boys Christmas&lt;/name&gt; &lt;released&gt;2009&lt;/released&gt; &lt;availability&gt; &lt;territories&gt;AT BE CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU NL NO PL PT RO SE SI SK&lt;/territories&gt; &lt;/availability&gt; &lt;/album&gt; &lt;track-number&gt;4&lt;/track-number&gt; &lt;length&gt;333.507000&lt;/length&gt; &lt;popularity&gt;0.51961&lt;/popularity&gt; &lt;/track&gt; &lt;/tracks&gt; </code></pre> <p>If we pretend that user_information=tracks user=track url=href lastname=artist.</p> <p>Hope this helps!</p> <p><strong>EDIT2:</strong> I solved it using Xpath Document and namespaces. Thank you all for trying!</p>
    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. This table or related slice is empty.
    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