简体   繁体   English

选择两个xml标记内的所有元素

[英]Selecting all elements within two xml tags

Does anyone know of a way to extract the xml contents of a bookmark in word using c#. 有谁知道使用c#提取单词中书签的xml内容的方法。 I am trying to do some string replacement at a bookmark using openxml and am unable to select all the elements betwen a bookmark start and bookmark end tag. 我正在尝试使用openxml在书签中进行一些字符串替换,并且无法选择书签开始和书签结束标记之间的所有元素。

Thanks 谢谢

The issue here is not reading the XML Tree into memory but actually getting the nodes between two xml nodes. 这里的问题不是将XML树读入内存,而是实际上使两个xml节点之间的节点。 The start and end node of the xml document in ooxml are solo meaning there are no child nodes. ooxml中xml文档的开始和结束节点是单独的,意味着没有子节点。 These simply state there is the beginning of a bookmark and an end of a bookmark. 这些只是声明书签的开头和书签的结尾。 It would make more sense to me if everything encapsulated in the bookmark would be a child node of a bookmark node rather than the current use of the xml tags. 如果封装在书签中的所有内容都是书签节点的子节点,而不是当前使用的xml标记,那么对我来说更有意义。

Since xPath navigation doesnt really work well with this concept one thing you could do is loop through each node in the xDoc and look for the bookmarkstart and end tags. 由于xPath导航在该概念上不能很好地工作,因此您可以做的一件事是遍历xDoc中的每个节点,并查找bookmarkstart和end标签。 Adding everything betewwn the two to an array or a new xDoc. 将两者之间的所有内容添加到数组或新的xDoc中。 From that point you can further parse the nodes to get the data you need. 从那时起,您可以进一步解析节点以获取所需的数据。 Hope that makes sense. 希望有道理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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