I am at a loss on how to parse xml, I understand the basics of a standard feed, however I have ran across one that I cannot for the life me figure out how to parse.

any input would be greatly appreciated.

thanks

this is the format and actually this is the entire contents of the xml (ids have been changed)
-------------------------------------Begin XML-----------------------------------------------------
- <XML>
<view id="value1" value="799" />
<view id="id2" value="48336" />
<view id="id3" value="6224" />
<view id="id4" value="8229" />
<view id="id5" value="7123321" />
<view id="id6" value="926" />
<view id="thisis7" value="220" />
<view id="number8" value="22112" />
<view id="lookingat9" value="3324" />
<view id="findnumber10" value="33223" />
<view id="number11" value="4784" />
</XML>

------------------------------------End XML -------------------------------------------------------

could someone please provide me a simple solution to parse this type of xml layout?

it would be greatly appreciated would be even better to explain how it works but then again.

thanks for any help

    What's the difficulty you're having? That looks almost too simple to be worth using XML for.

      what I am in need of is a simple method of reading that information (stored as a asp file), and create an array with all the variables in the format of:

      variable[id] = value['id']

      basically need a array with the ID as variable names, and the value as the value of the associated name

      if that makes sense.

      (sorry about the way I am putting this I can be a hack when it comes to wording things).

        found this in the forums and it at least counts the number of elements, however I am not understanding how to change it so I can get it to work properly.

        <?php
        $compiled_langs = array();
        $interprt_langs = array();
        $flag = "";
        $count = 0;

        function opening_element($parser, $element, $attributes) {
        / opening XML element callback function /

        global $flag;

        if ($element == "id")
        $flag = $attributes["value"];
        }

        function closing_element($parser, $element) {
        / closing XML element callback function /

        global $flag;

        if ($element == "view")
        $flag = "id";
        }

        function character_data($parser, $data) {
        / callback function for character data /

        global $flag;

        if ($flag == "id") {
        global $compiled_langs;
        $compiled_langs[] = $data;
        }

        if ($flag == "value") {
        global $interprt_langs;
        $interprt_langs[] = $data;
        }
        }

        $parser = xml_parser_create();
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
        xml_set_element_handler($parser, "opening_element", "closing_element");
        xml_set_character_data_handler($parser, "character_data");

        $document = file("http://www.guild-wars.us/xmlfeed.txt");

        foreach ($document as $line) {
        xml_parse($parser, $line);
        }

        xml_parser_free($parser);

        echo "The following compiled languages were found...<br />";
        foreach ($compiled_langs as $name) {
        $count++;
        echo "$count. $name <br />";
        }
        echo "<br />";

        $count = 0;
        echo "The following interpreted languages were found...<br />";
        foreach ($interprt_langs as $name) {
        $count++;
        echo "$count. $name <br />";
        }
        ?>

        any help would be greatly appreciated.

          Have a look at the [man]XML[/man] functions. Or even look at the user notes on that page for XML parsers that don't use expat. For example, one post there says "...this function parses a string of XML, creating nested arrays and attributes."

            Write a Reply...