XMLParse not returning any data

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
JoeBly
Newbie
Posts: 2
Joined: Tue Dec 04, 2018 12:29 am

XMLParse not returning any data

Post by JoeBly » Tue Dec 04, 2018 5:54 am

Hey there...

I'm banging my head against the desk trying to get XMLParse to work. I've tried multiple formats based on the examples as well as the tutorials at the w3schools. I just can't get this to work. Any insights?

LabelToVar>XML,strXML

//Get the number of recordings
XMLParse>strXML,/metadata/recording-list/@count,val,numList
//shows 0, expecting 1
mdl>%numList%
//shows blank, expecting 2
mdl>%val%

//Get the album title for the first recording that scores 100
XMLParse>strXML,/metadata/recording-list/recording[@score='100'][1]/release-list/release[1]/title/text(),val,numList
//shows 0, but expecting 1
mdl>%numList%
//shows blank, but expecting "Acoustic Disc: 100% Handmade Music, Volume VI"
mdl>%val%

//Get the release ID
XMLParse>strXML,/metadata/recording-list/recording[@score='100'][1]/release-list/release[1]/@id,val,numList
//shows 0, expecting 1
mdl>%numList%
//shows blank, expecting "9b51f621-81c6-4fe0-aefb-a341f7e05a5a"
mdl>%val%

/*
XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata created="2018-12-03T23:02:52.330Z" xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ns2="http://musicbrainz.org/ns/ext#-2.0">
<recording-list count="2" offset="0">
<recording id="8292f635-5e41-4aeb-8a12-b16ddf358ff6" ns2:score="100">
<title>Oh, Mio Babbino Caro</title>
<length>141666</length>
<artist-credit>
<name-credit joinphrase=" feat. ">
<artist id="8c52746b-5697-48ba-906e-5c2cd732a5e5">
<name>Beppe Gambetta</name>
<sort-name>Gambetta, Beppe</sort-name>
</artist>
</name-credit>
<name-credit>
<artist id="e3103b3b-0f1e-484c-9004-90bbafea6c08">
<name>Carlo Aonzo</name>
<sort-name>Aonzo, Carlo</sort-name>
</artist>
</name-credit>
</artist-credit>
<release-list>
<release id="9b51f621-81c6-4fe0-aefb-a341f7e05a5a">
<title>Acoustic Disc: 100% Handmade Music, Volume VI</title>
<status>Official</status>
<artist-credit>
<name-credit>
<artist id="89ad4ac3-39f7-470e-963a-56509c546377">
<name>Various Artists</name>
<sort-name>Various Artists</sort-name>
<disambiguation>add compilations to this artist</disambiguation>
</artist>
</name-credit>
</artist-credit>
<release-group id="087412fb-1166-37e1-832f-2d0c8a09f762" type="Compilation" type-id="dd2a21e1-0c00-3729-a7a0-de60b84eb5d1">
<title>Acoustic Disc: 100% Handmade Music, Volume VI</title>
<primary-type id="f529b476-6e62-324f-b0aa-1f3e33d313fc">Album</primary-type>
<secondary-type-list>
<secondary-type id="dd2a21e1-0c00-3729-a7a0-de60b84eb5d1">Compilation</secondary-type>
</secondary-type-list>
</release-group>
<medium-list count="1">
<track-count>15</track-count>
<medium>
<position>1</position>
<format>CD</format>
<track-list count="15" offset="12">
<track id="233da992-63ca-31a1-a9e6-6ce3d63e9830">
<number>13</number>
<title>Oh, Mio Babbino Caro</title>
<length>141666</length>
</track>
</track-list>
</medium>
</medium-list>
</release>
</release-list>
</recording>
<recording id="91429915-9ccc-47e4-8825-0d1bac2f7a86" ns2:score="74">
<title>Oh, mio babbino caro (Oh, My Dear Daddy)</title>
<length>140733</length>
<artist-credit>
<name-credit joinphrase=", ">
<artist id="8c52746b-5697-48ba-906e-5c2cd732a5e5">
<name>Beppe Gambetta</name>
<sort-name>Gambetta, Beppe</sort-name>
</artist>
</name-credit>
<name-credit joinphrase=" &amp; ">
<artist id="e3103b3b-0f1e-484c-9004-90bbafea6c08">
<name>Carlo Aonzo</name>
<sort-name>Aonzo, Carlo</sort-name>
</artist>
</name-credit>
<name-credit>
<artist id="402e4f4f-33aa-4b2b-9fdb-3cb4eb38f729">
<name>David Grisman</name>
<sort-name>Grisman, David</sort-name>
<alias-list>
<alias sort-name="Dave Grisman">Dave Grisman</alias>
</alias-list>
</artist>
</name-credit>
</artist-credit>
<release-list>
<release id="4f8cb5c9-ebcc-4565-bcfe-975c55b6612f">
<title>Traversata</title>
<status>Official</status>
<artist-credit>
<name-credit joinphrase=", ">
<artist id="8c52746b-5697-48ba-906e-5c2cd732a5e5">
<name>Beppe Gambetta</name>
<sort-name>Gambetta, Beppe</sort-name>
</artist>
</name-credit>
<name-credit joinphrase=" &amp; ">
<artist id="e3103b3b-0f1e-484c-9004-90bbafea6c08">
<name>Carlo Aonzo</name>
<sort-name>Aonzo, Carlo</sort-name>
</artist>
</name-credit>
<name-credit>
<artist id="402e4f4f-33aa-4b2b-9fdb-3cb4eb38f729">
<name>David Grisman</name>
<sort-name>Grisman, David</sort-name>
</artist>
</name-credit>
</artist-credit>
<release-group id="870da9f5-8e6c-3bf5-96d0-25315fcf1fdf" type="Album" type-id="f529b476-6e62-324f-b0aa-1f3e33d313fc">
<title>Traversata</title>
<primary-type id="f529b476-6e62-324f-b0aa-1f3e33d313fc">Album</primary-type>
</release-group>
<date>2001</date>
<country>US</country>
<release-event-list>
<release-event>
<date>2001</date>
<area id="489ce91b-6658-3307-9877-795b68554c98">
<name>United States</name>
<sort-name>United States</sort-name>
<iso-3166-1-code-list>
<iso-3166-1-code>US</iso-3166-1-code>
</iso-3166-1-code-list>
</area>
</release-event>
</release-event-list>
<medium-list count="1">
<track-count>15</track-count>
<medium>
<position>1</position>
<format>CD</format>
<track-list count="15" offset="1">
<track id="24a2a071-da74-386e-a015-ce5d8cabb50b">
<number>2</number>
<title>Oh, mio babbino caro (Oh, My Dear Daddy)</title>
<length>140733</length>
</track>
</track-list>
</medium>
</medium-list>
</release>
</release-list>
</recording>
</recording-list>
</metadata>
*/

User avatar
Marcus Tettmar
Site Admin
Posts: 7029
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: XMLParse not returning any data

Post by Marcus Tettmar » Wed Dec 05, 2018 8:49 pm

The issue is the namespace (xmlns attribute). If you remove it, it will work. So the metadata line becomes:

Code: Select all

<metadata created="2018-12-03T23:02:52.330Z" xmlns:ns2="http://musicbrainz.org/ns/ext#-2.0">
You could do a RegEx replace StringReplace.

If you cannot/don't want to remove it you can tell it to look at the local-names like this instead:

Code: Select all

XMLparse>strXML,/*[local-name()='metadata']/*[local-name()='recording-list']/*[local-name()='recording'],val,numList
See:
https://stackoverflow.com/questions/523 ... th/5239991
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

JoeBly
Newbie
Posts: 2
Joined: Tue Dec 04, 2018 12:29 am

Re: XMLParse not returning any data

Post by JoeBly » Thu Dec 06, 2018 3:27 am

Thanks, Marcus.
I did eventually figure it out on my own after another half-hour, and I did use RegEx out the namespace declarations and downstream NS references. The parsing works fine now.
-Joe

Post Reply