I am new to powershell and i am trying to access external entity of an xml document from powershell. Originally I have a document that looks as follows:
<?xml version=“1.0” encoding=“UTF-8”?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>
<par1>Don’t forget me this weekend!</par1>
</body>
</note>
this document is saved with file name mymessage.txt and i can access the content of par1 tag from powershell as
$xmlFileName = 'E:\mymessage.txt' [xml]$xmlDoc = Get-Content $xmlFileName Write-Host $xmlDoc.note.body.par1
This works fine. Now I want to breakdown the xml document into two. This is basically by accessing the second xml file as external entity. I put the body part in separate file called mymessage_body.txt and it looks
<?xml version="1.0" encoding="UTF-8"?> <DOCTYPE body [ <!ELEMENT body (par1)> <!ELEMENT par1 (#PCDATA)> ]> <body> <par1>Don't forget me this weekend!</par1> </body>
Similarly i put the header part in another file (called mymessage_header.txt ) and it looks
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE note [ <!ELEMENT note ANY> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ENTITY body SYSTEM "mymessage_body.txt"> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> &body; </note>
Now i tried to access the content of par1 from powershell as shown below and it returns nothing.
$xmlFileName = 'E:\mymessage_header.txt' [xml]$xmlDoc = Get-Content $xmlFileName Write-Host $xmlDoc.note.body.par1
I want to know weather the external entity is properly loaded or not. Would you please forward your suggestion in resolving this? Thanks!