I am using XML files as configuration files for my PowerShell scripts based on the blog post found at rkeithhill.wordpress.com. Some of my scripts shares the same settings and I would like to include those settings from an external XML file. What I have done is:
<?xml version="1.0" standalone="no" ?> <!DOCTYPE doc [ <!ENTITY shareddata SYSTEM "shared.xml"> ]> <configuration > <appSettings > &shareddata; <add key="motorcycle" value="Husqvarna TE610" /> <add key="car" value="Ford Mondeo" /> </appSettings> </configuration>
and the shared.xml file contains (one line only):
<add key="backhoe" value="Volvo BM 430 Hymas" />
Using the following code snippet I load the XML and print it to the console:
$config = [xml](get-content $path) $text = $config.OuterXml Write-Verbose "[LoadConfig] $text"
The output is:
VERBOSE: [LoadConfig] <?xml version="1.0" standalone="no"?> <!DOCTYPE doc[ <!ENTITY shareddata SYSTEM "shared.xml"> ]> <configuration><appSettings>&shareddata; <add key="motorcycle" value="Husqvarna TE610" /> <add key="car" value="Ford Mondeo" /></appSettings> </configuration>
The way I load the XML does not include the content of shared.xml, but it does parse the DOCTYPE tag, since if I revert to an invalid file it will fail.
So, how could I get PowerShell to fully include the XML snippet, so that loadconfig will find the key and value for my backhoe as well?
I have also tried
$Document = ( Select-Xml -Path myfile.xml -XPath / ).Node
but it won't load anything as long as I have the &shareddata; in the config file: