简体   繁体   中英

find attribute value using element value

following is my XML where i need to find Changeset attribute value of (Id) using <id> value of <task>/id value using Xpath.

i have tried the followin query "ReleaseNotes/ChangeSets/ChangeSet[Comments/checkintext/task/id ='" + jiraId + "']" where jiraId is <task>id value

<?xml version="1.0" encoding="utf-8"?>
<ReleaseNotes>
    <AxVersion>6.2.1000.1437</AxVersion>
    <FromDate>2/1/2015 12:00:00 AM</FromDate>
    <ToDate>2/26/2015 12:00:00 AM</ToDate>
    <ChangeSets>
        <ChangeSet Id="3600">
            <CheckInUserId>XXX\yy</CheckInUserId>
            <Comments>
                <checkintext>
                    <bpcheckdeviated>true</bpcheckdeviated>
                    <task>
                        <id>CS-2215</id>
                        <name>Small performance improvements in hedge qty lookup.</name>
                        <version>V6.0</version>
                        <sprint>17.8</sprint>
                        <project>Cs2215_Mpv_HedgeQtyLookupPerformance</project>
                        <area>Others</area>
                        <taskstatus>Closed</taskstatus>
                    </task>
                    <text>
                        Few small performance improvements in queries.
                    </text>
                    <notes>
                        <note>
                            <section>Info</section>
                            <component></component>
                            <text></text>
                        </note>
                    </notes>
                </checkintext>
            </Comments>
            <Components>
                <Component>
                    <Name>CsMpvCalcMatQtyHedgeBase.xpo</Name>
                    <Type>Classes</Type>
                    <Action>Edit</Action>
                    <Models>
                        <Model Id="I4C" Layer="ISV" />
                    </Models>
                </Component>
                <Component>
                    <Name>CsMpvInsertMatQtyDetails_Agreement.xpo</Name>
                    <Type>Classes</Type>
                    <Action>Edit</Action>
                    <Models>
                        <Model Id="I4C" Layer="ISV" />
                    </Models>
                </Component>
                <Component>
                    <Name>Cs2215_Mpv_HedgeQtyLookupPerformance.xpo</Name>
                    <Type>Shared</Type>
                    <Action>Add</Action>
                    <Models />
                </Component>
            </Components>
        </ChangeSet>
    </ChangeSets>
</ReleaseNotes>

HOw to find the attribute value Thanks in advance..

You're almost there:

ReleaseNotes/ChangeSets/ChangeSet[Comments/checkintext/task/id[text()='CS-2215']]

(Note: I used an online XPath fiddle tool to find this.)

This should also work.

//ChangeSet[.//id[text()='CS-2215']]

Gets all changesets who has a child id with a specific text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM