1
我試圖通過使用XPath查詢值訪問元素,以便以後更新其值,儘管XML文件很簡單,但無法找到正確的查詢。xpath查詢以按值更新元素
例如:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<OBJECTID>1</OBJECTID>
<TABLE_PK>IN</TABLE_PK>
<FIELD_PK>AC_TR_OID</FIELD_PK>
<TABLE_FK></TABLE_FK>
</row>
<row>
<OBJECTID>2</OBJECTID>
<TABLE_PK>ARQUETAP</TABLE_PK>
<FIELD_PK>ARP_AR_OID</FIELD_PK>
<TABLE_FK>ARQ</TABLE_FK>
</row>
<row>
<OBJECTID>3</OBJECTID>
<TABLE_PK>ACOMRUR</TABLE_PK>
<FIELD_PK>ACR_TR_OID</FIELD_PK>
<TABLE_FK>PASS</TABLE_FK>
</row>
<row>
<OBJECTID>4</OBJECTID>
<TABLE_PK>ACOMRUR</TABLE_PK>
<FIELD_PK>ACR_RA_OID</FIELD_PK>
<TABLE_FK>WRANCH</TABLE_FK>
</row>
<row>
<OBJECTID>5</OBJECTID>
<TABLE_PK>ACTUATION</TABLE_PK>
<FIELD_PK>ACT_ACTUATIONP_OID</FIELD_PK>
<TABLE_FK>ACTUATIONP</TABLE_FK>
</row>
</root>
我只是想通過一個可以訪問的元素之一,例如: 稱爲ACOMRUR數排3用一個新值更新TABLE_PK元素取代ACOMRUR, /根/行[3]/OBJETID [文本()= 'ACOMRUR'] /根/行/ TABLE_PK [文本()= 'ACOMRUR']
我還與更復雜的查詢,嵌套的,邏輯運算符但沒有測試。 我將不勝感激任何建議 感謝,
/root/row [3]/OBJETID [text()='ACOMRUR'] –
/root/row/TABLE_PK [text()='ACOMRUR'] –
您可能需要提供[prefixes/mappings or brace URI文字](https://www.w3.org/TR/xpath-31/#id-basics)作爲'http:// www.w3.org/2001/XMLSchema-instance'命名空間。 – McDowell