Monday, 1 May 2017

Parse XML from Sonos

I am trying to parse the XML output from Sonos subscription I am doing this in Node.js I have tried two different npm modules, xml2js and libxmljs but i cant seem to get it right. All example that I have find is a simple XML but I am trying to parse a more advanced file and probably not much harder when you know how to handle it.

I hope someone could help me so that I understand how to tackle a file like this. In my example then I want the value 22 from:

<Volume channel="Master" val="22"/>

Here is the XML file

<e:propertyset
xmlns:e="urn:schemas-upnp-org:event-1-0">
<e:property>
    <LastChange>
        <Event
            xmlns="urn:schemas-upnp-org:metadata-1-0/RCS/">
            <InstanceID val="0">
                <Volume channel="Master" val="22"/>
                <Volume channel="LF" val="100"/>
                <Volume channel="RF" val="100"/>
                <Mute channel="Master" val="0"/>
                <Mute channel="LF" val="0"/>
                <Mute channel="RF" val="0"/>
                <Bass val="0"/>
                <Treble val="0"/>
                <Loudness channel="Master" val="1"/>
                <OutputFixed val="0"/>
                <HeadphoneConnected val="0"/>
                <SpeakerSize val="5"/>
                <SubGain val="0"/>
                <SubCrossover val="0"/>
                <SubPolarity val="0"/>
                <SubEnabled val="1"/>
                <SonarEnabled val="0"/>
                <SonarCalibrationAvailable val="0"/>
                <PresetNameList val="FactoryDefaults"/>
            </InstanceID>
        </Event>
    </LastChange>
</e:property>

Thanks.



via Kristoffer Isaksson

No comments:

Post a Comment