简体   繁体   中英

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#. 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.

Thanks

The issue here is not reading the XML Tree into memory but actually getting the nodes between two xml nodes. The start and end node of the xml document in ooxml are solo meaning there are no child nodes. 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.

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. Adding everything betewwn the two to an array or a new xDoc. From that point you can further parse the nodes to get the data you need. Hope that makes sense.

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