1

This is a complicated XPath problem I cannot figure out.

Suppose I have an XML Feed that contains many <event> nodes that look like this:

<bestlinesports_line_feed>
    <event>
    <event_datetimeGMT>2015-07-29 19:10</event_datetimeGMT>
        <sporttype>Baseball</sporttype>
        <scheduletext>null</scheduletext>
        <league>MLB Baseball</league>
        <participant>
            <participant_name>Washington Nationals</participant_name>
            <rotnum>905</rotnum>
            <visiting_home_draw>Visiting</visiting_home_draw>
            <odds>
                <moneyline>-124</moneyline>
            </odds>
            <pitcher>D. Fister -R</pitcher>
        </participant>
        <participant>
            <participant_name>Miami Marlins</participant_name>
            <rotnum>906</rotnum>
            <visiting_home_draw>Home</visiting_home_draw>
            <odds>
                <moneyline>114</moneyline>
            </odds>
            <pitcher>T. Koehler -R</pitcher>
            </participant>
            <drawrotnum>0</drawrotnum>
            <drawmoneyline>0</drawmoneyline>
            <drawTitle/>
        <period>
            <period_description>Game</period_description>
            <periodcutoff_datetimeGMT>2015-07-29 19:20</periodcutoff_datetimeGMT>
            <period_status>O</period_status>
            <spread>
                <spread_visiting>-1.5</spread_visiting>
                <spread_adjust_visiting>125</spread_adjust_visiting>
                <spread_home>1.5</spread_home>
                <spread_adjust_home>-145</spread_adjust_home>
            </spread>
            <total>
                <total_points>7.5</total_points>
                <over_adjust>-102</over_adjust>
                <under_adjust>-118</under_adjust>
            </total>
        </period>
    </event>

Now, there are 6 of these Washington Nationals event nodes. I'd like to target this specific one based on 4 criteria:

  • <participant_name> contains 'Nationals' (this narrows it down to 6) (this needs to be contains because they connect with my Rails model that == 'Nationals')
  • <event_datetimeGMT> contains '2015-07-29' (this narrows it down to 5) (needs to be contains as well because of my Rails game_date model)
  • <league> is 'MLB Baseball' (narrows it down to 2)
  • <period_description> is 'Game' (narrows it down to the 1)

This would be a HUGE help. XPath is really hard!

If you're feeling especially gracious, the 3 strings/values I am going to target once I have the parent event node selected are: <moneyline> under the home team, the second participant or Miami Marlins (there are two moneylines), then <total_points> and <spread_home>. This xml is a little wonky so it makes it harder.

Thank you so very much.

1 Answer 1

2

You can try this way (formatted for readability) :

//event
[
    participant/participant_name[contains(.,'Nationals')]
]
[
    event_datetimeGMT[contains(.,'2015-07-29')]
]
[
    league='MLB Baseball'
]
[
    period/period_description='Game'
]

Each of the outer predicate ([....]), in order, implements each of the four criteria mentioned in the question.

And the following are 3 XPath expressions for getting the 3 string values you want, given the targeted <event> as context node :

./participant[visiting_home_draw='Home']/odds/moneyline
./period/total/total_points
./period/spread/spread_home
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.