How to locate node by line/offset and add a child node

SyntaxEditor for WPF Forum

Posted 6 years ago by Glenn Engel
Version: 14.2.0611

Given a line-number and line-offset for an element in an xml document, how would I go about inserting a child node at that point in the document?  I'm currently viewing and editing the document with an EditorDocument instance but am receiving the line-number/line-pos from another source.   Alternatively, given that I know the parent element is the Nth element defined in the document, how would I find this in the EditorDocument and insert a child node?

Comments (1)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA


Line/character pair data is what we call a TextPosition.  Check out our "SyntaxEditor / Text/Parsing Framework / Offsets, Ranges, and Positions" topic in the documentation that comes with SyntaxEditor.  That has a section in it that tells you how to convert a TextPosition to an offset.  Once you have an offset, you'd be able to call the document modification methods, which are described in the "Text Changes and Operations" topic.

If you are using the advanced XML language in our Web Languages Add-on, you could take a look at the AST that its parser generates for the document.  The AST is available on the document's ParseData and is a tree of AST nodes.  You could recurse that and then get the appropriate node's end tag offset to know where it's at.

Actipro Software Support

The latest build of this product (v2020.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.