How do I get the Nth item of a XML file?

0 favourites
  • 2 posts
From the Asset Store
Cartoon Funny Item Interface Sound Pack comes with 426 high-quality sound effects
  • Hi there construct community,

    I do have the next XML file; I have used Ajax to load the XML file; then load XML info using AJAX.LastData.

    I want to get the info of the XML items "Level" by number order, but the items don't have a tag to pick them up by number, instead they have string names, how can I achieve that?

    I tried this to pick the first level (Item[1]) but with no success "XML.StringValue("/FreePack/LevelCollection/Level[1]/text()")"

    Any help would be appreciated!!

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <FreePack>

    <LevelCollection MaxWidth="11" MaxHeight="12">

    <Level Id="Con" Width="9" Height="2">

    <L> # #</L>

    <L> #####</L>

    </Level>

    <Level Id="Roo" Width="11" Height="2">

    <L># #</L>

    <L>###########</L>

    </Level>

    <Level Id="Jor" Width="9" Height="2">

    <L> ## #</L>

    <L> ####</L>

    </Level>

    </LevelCollection>

    </FreePack>

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm no expert, but I've been messing around with XPath and maybe I can help.

    First of all, text() will just grab contents of a node.

    Therefore "/FreePack/LevelCollection/Level[1]/text()" will try and grab the text contents of the first <Level> node, but there is nothing there to be grabbed!

    (For the following examples, I'll assume that when you said Item, you were referring to <L> nodes.)

    If instead you use "/FreePack/LevelCollection/Level[1]/*/text()" or "/FreePack/LevelCollection/Level[1]/L/text()", you'll grab a sequence of all the contents from each <L> inside the first <Level> node.

    "/FreePack/LevelCollection/Level[1]/L[1]/text()", on the other hand, will get you the contents of a single chosen <L>

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)