Powershell v2 and XML: How to include a XML snippet into a XML document

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 prints it to 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 refert 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


Source: xml

Leave a Reply