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 &quot;server&quot; set default.</description>     </context-param> </web-app> 
$gcxml = get-content -path "c:\temp.xml" write-output $gcxml 

the &quot; preserved in code above, not in code below:

$xdoc = [xml] $gcxml $xdoc.'web-app'.'context-param'.'description' 

here &quot; being parsed ", don't want. output is:

only applicable if "server" set default.

how can preserve &quot;?

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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -