powershell - casting to XML by default parsing HTML tags too -
i have xml document contains
<?xml version="1.0" encoding="utf-8"?> <web-app> <context-param> <description>only applicable if "server" set default.</description> </context-param> </web-app>
$gcxml = get-content -path "c:\temp.xml" write-output $gcxml
the "
preserved in code above, not in code below:
$xdoc = [xml] $gcxml $xdoc.'web-app'.'context-param'.'description'
here "
being parsed "
, don't want. output is:
only applicable if "server" set default.
how can preserve "
?
you might re-encode string if that's need , not wish (or cannot) change xml content:
# load system.web assembly add-type -assembly system.web [system.web.httputility]::htmlencode($xdoc.'web-app'.'context-param'.'description')
versions of powershell older 5 may need additional parentheses surrounding complex value:
[system.web.httputility]::htmlencode(($xdoc.'web-app'.'context-param'.'description'))
Comments
Post a Comment