Converting XmlSchema to string
Here’s a snippet which has saved me a great deal of time lately. It’s a simple function which takes in a XmlSchema-object and returns it in a string-format.
<span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #0000ff">Private</span> <span style="color: #0000ff">Function</span> SchemaAsString(<span style="color: #0000ff">ByVal</span> schema <span style="color: #0000ff">As</span> XmlSchema) <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
<span id="lnum2" style="color: #606060"> 2:</span>
<span id="lnum3" style="color: #606060"> 3:</span> Using memStream <span style="color: #0000ff">As</span> <span style="color: #0000ff">New</span> MemoryStream(1024)
<span id="lnum4" style="color: #606060"> 4:</span>
<span id="lnum5" style="color: #606060"> 5:</span> schema.Write(memStream)
<span id="lnum6" style="color: #606060"> 6:</span> memStream.Seek(0, SeekOrigin.Begin)
<span id="lnum7" style="color: #606060"> 7:</span>
<span id="lnum8" style="color: #606060"> 8:</span> Using reader <span style="color: #0000ff">As</span> <span style="color: #0000ff">New</span> StreamReader(memStream)
<span id="lnum9" style="color: #606060"> 9:</span>
<span id="lnum10" style="color: #606060"> 10:</span> <span style="color: #0000ff">Dim</span> result = reader.ReadToEnd
<span id="lnum11" style="color: #606060"> 11:</span> <span style="color: #0000ff">Return</span> result
<span id="lnum12" style="color: #606060"> 12:</span>
<span id="lnum13" style="color: #606060"> 13:</span> <span style="color: #0000ff">End</span> Using
<span id="lnum14" style="color: #606060"> 14:</span>
<span id="lnum15" style="color: #606060"> 15:</span> <span style="color: #0000ff">End</span> Using
<span id="lnum16" style="color: #606060"> 16:</span>
<span id="lnum17" style="color: #606060"> 17:</span> <span style="color: #0000ff">End</span> Function
This is useful if you obtain a XmlSchema-object from somewhere and want to do some Linq to Xml queries over it.
The original code was found from the StackOverflow.