XPath:获取其中一个子元素具有某些条件的元素

时间:2017-12-30 15:48:33

标签: xml xpath

我有以下数据:

./bin/console doctrine:migrations:migrate

我试图获取行及其子元素,其中包含属性“name”= rowuuid的字段,其值为b93c6113-7508-42aa-8549-267f0956b935

我有点卡在这里:我试过了:

<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="acgg_onfarm">
        <table_data name="birdentext_maintable">
        <row>
                <field name="surveyid">95419b4f-006f-44c4-b83d-bc6e0ef18478</field>
                <field name="originid">FORMHUB-JSON</field>
                <field name="meta_devid">865770027212853</field>
                <field name="start_time">2017-07-26 14:31:07</field>
                <field name="survey_date">2017-07-14 00:00:00</field>
                <field name="date_yyyymmdd">20170714</field>
                <field name="subscriber_id" xsi:nil="true" />
                <field name="phone_number">0947428980</field>
                <field name="end_time">2017-07-26 14:32:31</field>
                <field name="onfarm_country">E</field>
                <field name="onfarm_subnatarea">AA</field>
                <field name="onfarm_village">198</field>
                <field name="onfarm_enum">198</field>
                <field name="householdid">EAA2001</field>
                <field name="householdid_key">EAA2001_20170714</field>
                <field name="bent_general">0</field>
                <field name="bext_general">1</field>
                <field name="rowuuid">7fbf04b1-7fd6-4920-9a1f-8d375020af1b</field>
        </row>
        <row>
                <field name="surveyid">e5d2810e-2db4-40ef-baf0-15c77d31797a</field>
                <field name="originid">FORMHUB-JSON</field>
                <field name="meta_devid">865770027212853</field>
                <field name="start_time">2017-08-14 05:13:49</field>
                <field name="survey_date">2017-08-14 00:00:00</field>
                <field name="date_yyyymmdd">20170814</field>
                <field name="subscriber_id" xsi:nil="true" />
                <field name="phone_number">0947428980</field>
                <field name="end_time">2017-08-14 05:15:08</field>
                <field name="onfarm_country">E</field>
                <field name="onfarm_subnatarea">AA</field>
                <field name="onfarm_village">198</field>
                <field name="onfarm_enum">198</field>
                <field name="householdid">EAA2001</field>
                <field name="householdid_key">EAA2001_20170814</field>
                <field name="bent_general">0</field>
                <field name="bext_general">1</field>
                <field name="rowuuid">1070fb2c-58b2-4155-84a8-ec40ef669919</field>
        </row>
    </table_data>
</database>

但这只能归还......

感谢任何帮助

1 个答案:

答案 0 :(得分:0)

这个XPath,

//row[field[@name='rowuuid' and .='b93c6113-7508-42aa-8549-267f0956b935']]

将返回所有row元素,其中包含名为field的子rowuuid元素,其字符串值为b93c6113-7508-42aa-8549-267f0956b935