Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Not able to convert xml string to XmlDocument object

$
0
0

I am reading xml content from xml file which is present in JAR file.

To read the xml content my code part is this:

#Asume there is one xml file "books.xml" in Jar file

$filename="books.xml"

$filepath = "C:\Users\awa\Documents\PowerShell\MockDiscovery.jar"

[Void][Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') $rawFiles = [IO.Compression.ZipFile]::OpenRead($filepath).Entries

foreach($file in $rawFiles){

if($file.FullName.EndsWith($filename))

{

[System.IO.Stream]$iostream = $file.Open()

if($iostream.CanRead)

{

[int] $count = 1024

$buffer = New-Object Byte[] $count

[int] $offset = 0

[System.String]$filecontent = ""

while($iostream.Read($buffer, $offset, $count) -gt 0 )

{

$filecontent += [System.Text.Encoding]::Default.GetString($buffer)

$buffer = New-Object Byte[] $count

}

$iostream.close()

}

}

After execution of this code part i get the content of books.xml in $filecontent.

Now  i am converting this string xml content to XmlDocument object. To do this i tried following technique

1) $xml = [xml]$filecontent

2)$xml = [xml]@"

$filecontent

"@

by using any of both i am not able to covert it.

the exception message i am getting is :

Cannot convert value "<content of the xml file>

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles