raj
raj

Reputation: 33

Read xml files using Powershell XMLReader without locking the xml file

I am looking to read xml files using xmlreader without causing lock on the file. all my operations are read only

$reader= system.Xml.XmlReader]::Create($xmlfile)

whenever I use $reader.read() I can't seem to get another thread read the same file.. any help is much appreciated.

Upvotes: 2

Views: 2549

Answers (1)

Keith Hill
Keith Hill

Reputation: 201692

Read the file into a string, wrap the string in a StringReader and pass that to the XmlReader.Create method e.g.:

$str = Get-Content C:\temp\foo.xml -Raw
$stringReader = new-object system.io.stringreader $str
$xmlReader = [system.xml.xmlreader]::Create($stringReader)

Upvotes: 2

Related Questions