It assumes that you have a boolean variable called IsFragment which
indicates the kind of Xml you are dealing with (either a well-formed
document or just a fragment), because these are read out differently.
You can use this example to get the content of your XmlReader into a
string:
XmlReader reader = o.ExecuteXmlReader(); //uses a SqlCommand to get an
XmlReader, for example, from SQL Server. You can also use the
constructor of the XmlTextReader
StringBuilder XmlStringB = new StringBuilder();
if (!IsFragment)
{
reader.MoveToContent();
XmlStringB.Append(reader.ReadOuterXml());
}
else
{
while (reader.Read())
{
XmlStringB.Append(reader.ReadOuterXml());
}
}
return XmlStringB.ToString()
need a little more help getting this into vb (IsFragment ?)
Dim XmlStringB As New StringBuilder()
Dim reader as New DataSet()
reader.ReadXml(Server.MapPath("project.xml"))
If Not IsFragment Then
reader.MoveToContent()
XmlStringB.Append(reader.ReadOuterXml())
Else
While reader.Read()
XmlStringB.Append(reader.ReadOuterXml())
End While
End If
Return XmlStringB.ToString()
The IsFragment is just a boolean type variable is declare in my code.
Basically, I use it because of the way the Xml is read in the if/else
that follows. So, if you know your Xml is always well-formed, just do:
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.