Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Ok, so this bugs me. Why do I need to load an [xml] file twice to have it read correctly?

$
0
0

To explain.
I have an .xml file that I need to pull values from and later update. If I “get-content” into a variable just once, all I get back is the literal contents into that variable. I have to load it twice to be able to “use” it.

ex.

$xml = [xml]$xmldocument = get-content "C:appConfigsappNameapplication.config.xml" 

Looking at the variable $xml results in the literal text and I can’t pull or add values based on nodes:

$xml <?xml version="1.0"?> <configuration> <configProtectedData /> <connectionStrings /> <oracle.manageddataaccess.client /> <system.diagnostics /> <system.windows.forms /> <uri /> <appSettings> <add key="name" value="xxxx" /> <add key="name2" value="xxxx" /> ..... 

Yet, if I load the file a second time, then I get the expected result and can now manipulate the nodes with no problem.

xml configuration --- ------------- version="1.0" configuration 

Loading it twice isn’t really a big issue, but it bothers me that it has to be done at all and I don’t understand what’s happening.

submitted by /u/mkhopper
[link] [comments]

The post Ok, so this bugs me. Why do I need to load an [xml] file twice to have it read correctly? appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles