0

I want to create a list from a php xml file, so I read some tutorials and put together this:

$.blockUI();

           $.get('venuesxml.php', function (data) {

                $('#MenuList').append("<p><label><strong>Id</strong></label>
                                     <label><strong>venue type</strong></label></p>");

                $(data).find('marker').each(function () {

                    $('#MenuList').append("<p><label>" +

                    $(this).find('ID').text() + "</label><label>" +

                    $(this).find('venue_type').text() + "</label></p>");

                });

            });

            $.unblockUI();

However I noticed that this will only work if the xml looks like this:

<markers>
  <marker>

    <ID>1</ID>

    <venue_type>2</Name>

  </marker>
</markers>

However it looks like this:

<markers>
     <marker id="67" venue_type="2"/>
</markers>

How would I get the data in this case? Thanks

3 Answers 3

1

You want to retrieve the XML attributes instead of nodes within <marker>

Try replacing $(this).find('ID').text() with $(this).attr('id') and $(this).find('venue_type').text() with $(this).attr('venue_type')

Sign up to request clarification or add additional context in comments.

Comments

1

try changing with this and see if this works for you:

$(this).text($(this).attr('id')) + "</label><label>" +

$(this).text($(this).attr('venue_type')) + "</label></p>");

Comments

1

You can use attr method:

$(data).find('marker').each(function () {
    var p = "<p>" +
               "<label>" + $(this).attr('id') + "</label>" +
               "<label>" + $(this).attr('venue_type') + "</label>" +
            "</p>"; 
    $('#MenuList').append(p)
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.