问题
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