1

I have an XML document that I want to search a specific date and get information for just that date. My XML looks like this:

    <month id="01">
        <day id="1">
            <eitem type="dayinfo">
                <caption>
                    <text lang="cy">f. 3 r.</text>
                    <text lang="en">f. 3 r.</text>
                </caption>
                <ref href="link" id="3"/>
                <thumb href="link" id="3"/>
            </eitem>
        </day>
        <day id="7">
            <eitem type="dayinfo">
                <caption>
                    <text lang="cy">f. 5 v.</text>
                    <text lang="en">f. 5 v.</text>
                </caption>
                <ref href="link" id="4"/>
                <thumb href="link" id="4"/>
            </eitem>
        </day>
        <day id="28">
            <eitem type="dayinfo2">
                <caption id="1">
                    <text lang="cy">test</text>
                    <text lang="en">test2</text>
                </caption>
                <ref href="link" id="1"/>
                <thumb href="link" id="1"/>
            </eitem>
        </day>
        <day id="28">
            <eitem type="dayinfo">
                <caption>
                    <text lang="cy">f. 14 v.</text>
                    <text lang="en">f. 14 v.</text>
                </caption>
                <ref href="link" id="20"/>
                <thumb href="link" id="20"/>
            </eitem>
        </day>
    </month>

My Jquery looks like this:

            $(xml).find('month[id=01]').each(function()
            {
                $(xml).find("day").each(function()
                {
                    var day = $(this).attr('id');
                    alert(day);
                });
            });

In the XML example above I only shown one month, however there are many more. In my JQuery I've tried to do 'Where month = 1' and get all the days info for that month, however that JQuery brings back days for every month. How do I do a where clause with JQuery/JavaScript on a XML document? thanks.

1 Answer 1

2
   $(xml).find('month[id=01]').each(function()
        {
            $(this).find("day").each(function()
          //  ^^^^
            {
                var day = $(this).attr('id');
                alert(day);
            });
        });
Sign up to request clarification or add additional context in comments.

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.