XmlDocument to XmlReader?

StewartBW 825 Reputation points
2024-07-13T23:12:42.57+00:00

Hello

I used to load an XML file into an XDocument and keep it intact in memory, then pass it to another object when needed, since it only accepts XmlReader, I was using XDocument.CreateReader.

Now am moving from XDocument to XmlDocument, just no idea how to pass the XmlDocument as XmlReader.

Found this snippet on a website and am not sure if this is the correct way to go?

It uses XmlNodeReader not XmlReader, and although it is accepted, the XML data will be intact and this will result the same as using XDocument.CreateReader?

Thanks in advance :)

Dim xml As New XmlDocument()
Using xnr As New XmlNodeReader(xml)
	Pass xnr as XmlReader ???
End Using
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,601 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,654 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more