验证XML字符串在VB.NET [英] Validating XML String in VB.NET
问题描述
请注意,我是很新的.NET和ASP.NET。
我试图从URL加载XML文本的脚本,我有困难搞清楚如何检查,看它是否有效,规范化的XML。我没有一个模式因为有几个变量,可以改变XML格式的,我只是想检查,以确保所有的开放标签的正确关闭,所以我可以确认整个字符串正确加载。以下是我现在所拥有的。
昏暗objResponse作为HttpWebResponse
昏暗objRequest由于HttpWebRequest的
昏暗strXml作为字符串
昏暗newMembers作为新的数据集
昏暗的XmlReader作为StringReader'得到当前文件的XML
objRequest = HttpWebRequest.Create(美语)
objResponse = objRequest.GetResponse()使用SR作为新的StreamReader(objResponse.GetResponseStream())
strXml = sr.ReadToEnd()
sr.Close()
使用完我想在这里补充一下,以验证strXML创建一个XML文件中的数据从远程服务器拉下来
newMembers =新的数据集()
的XMLReader =新System.IO.StringReader(strXml)
newMembers.ReadXml(的XMLReader)
您可以使用XMLDocument.load方法方法,如果失败,你可以假设它是不是有效的XML。
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)
这篇关于验证XML字符串在VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!