Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

XML

XmlNode.SelectNodes() always returns List in PowerShell 2.0

Problem: In PowerShell, by using XML DOM API in .NET, you can access to a child element in XML as a ordinary property. PS > $xml = New-Object System.Xml.XmlDocument PS > $xml.LoadXml('<a><b id="1">foo</b></a>') PS > $xml.SelectNodes('//a').b id #text -- ----- …

How to get a #text in XML even if the tag doesn't have attributes

Background: In PowerShell (even in C# or VB.NET?), you can get a body of the tag (text content) with '#text#' property. > $xml = New-Object System.Xml.XmlDocument > $xml.LoadXml('<a><b id="1">foo</b></a>') > $xml.SelectNodes('//a').b.'#text' foo Problem: If a …