DataSchema.XML for XML Data

DataSchema.XML normalizes arbitrary XML data against a given schema into an object with known properties.

Basic example

Data
<root>
    <session>34637542</session>
    <category name="music" id="5"><results>
        <song id="59672468">
            <title>I Kissed A Girl</title>
            <rank>1</rank>
            <artist id="30326214">Katy Perry</artist>
        </song>
        <song id="47973564">
            <title>Shake It</title>
            <rank>2</rank>
            <artist id="45575683">Metro Station</artist>
        </song>
        <song id="52207363">
            <title>Bleeding Love</title>
            <rank>3</rank>
            <artist id="37956508">Leona Lewis</artist>
        </song>
    </results></category>
</root>
    
Schema
{
    resultListLocator: "song",
    resultFields: [{key:"title"}, {key:"artist"}, {key:"rank"}]
}
    
Normalized data

Complex example

Data
<Response>
    <Session>542235629</Session>
    <Tracks  start="1" count="10" total="98" errorCount="0"
        defaultSort="popularity+" description="Top 100 Tracks"
        name="Top 100 Tracks">
        <Track id="59672468" rating="-1" title="I Kissed A Girl">
            <Artist id="30326214" rating="-1">Katy Perry</Artist>
            <ItemInfo><ChartPosition last="26" this="1"/></ItemInfo>
        </Track>
        <Track id="47973564" rating="-1" title="Shake It">
            <Artist id="45575683" rating="-1">Metro Station</Artist>
            <ItemInfo><ChartPosition last="27" this="2"/></ItemInfo>
        </Track>
        <Track id="52207363" rating="-1" title="Bleeding Love">
            <Artist id="37956508" rating="-1">Leona Lewis</Artist>
            <ItemInfo><ChartPosition last="28" this="3"/></ItemInfo>
        </Track>
    </Tracks>
</Response>
        
Schema
{
    metaFields: {session:"//Session", total:"//Tracks/@total"},
    resultListLocator: "Track",
    resultFields: [{key:"song", locator:"@title"},
        {key:"artist", locator:"Artist"},
        {key:"rank", locator:"ItemInfo/ChartPosition/@this"}]
}
    
Normalized data