Please note that I am very new to .NET and ASP.NET.
I have a script that attempts to load XML text from a URL and I am having difficulty figuring out how to check to see if it is valid, normalized XML. I don’t have a schema as there are several variables which could change the XML format, I just want to check to make sure all of the opening tags are closed properly so I can verify that the entire string loaded properly. Here is what I have right now.
Dim objResponse As HttpWebResponse
Dim objRequest As HttpWebRequest
Dim strXml As String
Dim newMembers As New DataSet
Dim xmlReader As StringReader
'get xml from current file
objRequest = HttpWebRequest.Create(xmlurl)
objResponse = objRequest.GetResponse()
Using sr As New StreamReader(objResponse.GetResponseStream())
strXml = sr.ReadToEnd()
sr.Close()
End Using
'I would like to add something here to validate strXML
' create a dataset from the XML file pulled down from the remote server
newMembers = New DataSet()
xmlReader = New System.IO.StringReader(strXml)
newMembers.ReadXml(xmlReader)
You can use the XmlDocument.Load method and if it fails, you can assume it’s not valid XML.
XmlDocument.Load Method (Stream)