How to get line number of selected node in xml using powershell

ぐ巨炮叔叔 提交于 2021-01-29 09:16:04

问题


I would want to get the line number of node which is changed/manipulated in XML using powershell.

$($node.LineNumber) doesn't seem to be working.

For example:

$node.ParentNode.InsertBefore($nodeToInsert, $node) //which inserts a node

I want to get the line number of this node.


回答1:


Lines and line numbers exist in the lexical XML that you supply as input to the XML parser. They don't exist (usually) in the tree of in-memory nodes that is output by the XML parser, and which your program is manipulating. Even if the nodes in the tree retain diagnostic information about the line numbers where they originally came from, it's certainly not a meaningful concept for nodes that are subsequently added to the tree.

You need to find a different way to solve whatever you are trying to accomplish.



来源:https://stackoverflow.com/questions/60665651/how-to-get-line-number-of-selected-node-in-xml-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!