Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 投影与保持结构_Xpath_Subset_Projection - Fatal编程技术网

Xpath 投影与保持结构

Xpath 投影与保持结构,xpath,subset,projection,Xpath,Subset,Projection,对于以下文档 <root> <child no=1> <grandchild no=1></grandchild> <grandchild no=2></grandchild> <grandchild no=3></grandchild> </child> <child no=2> <grandchild no=1></grandchil

对于以下文档

<root>
 <child no=1>
  <grandchild no=1></grandchild>
  <grandchild no=2></grandchild>
  <grandchild no=3></grandchild>
 </child>
 <child no=2>
  <grandchild no=1></grandchild>
  <grandchild no=2></grandchild>
  <grandchild no=3></grandchild>
  <grandchild no=4></grandchild>
 </child>
</root>
i、 孙辈不再包含在各自的子女中

非常感谢您的建议和指点!
bb

Xpath用于选择xml中的标记,而不是修改它。您想要修改子标记,而xpath无法修改


但是您可以使用
lxml
xml
库来解析xml并修改它。

Xpath用于选择xml中的标记,而不是修改它。您需要修改
子标记,而xpath无法修改。
<child no=1>
 <grandchild no=1></grandchild>
 <grandchild no=2></grandchild>
</child>
<child no=2>
 <grandchild no=1></grandchild>
 <grandchild no=2></grandchild>
</child>
 <grandchild no=1></grandchild>,
 <grandchild no=2></grandchild>,
 <grandchild no=1></grandchild>,
 <grandchild no=2></grandchild>