I want to read a xml file, and based on some xml structures I already know recognize the type of xml (xml 1, xml 2 or xml 3)
for example, I know 3 xml structures:
xml 1
<?xml version="1.0"?> <OS> <Info> ... </Info> </OS> xml 2
<?xml version="1.0" encoding="UTF-8"?> <SaData Version="2"> <Cli> ... </Cli> </SaData> xml 3
<?xml version="1.0" encoding="UTF-8"?> <Init> <Danit> ... </Danit> </Init> So far I have a class XMLBrandRecognitionNode that acts as a string enum for list of xmlTypes (I did it using a list because the number of xml types could grow, for now there are only 3 types)
Public Class XMLBrandRecognitionNode Private Key As String Public Shared ReadOnly xml1 As XMLBrandRecognitionNode = New XMLBrandRecognitionNode("/OS/Info") Public Shared ReadOnly xml2 As XMLBrandRecognitionNode = New XMLBrandRecognitionNode("/SaData/Cli") Public Shared ReadOnly xml3 As XMLBrandRecognitionNode = New XMLBrandRecognitionNode("/Init/Danit") Private Sub New(ByVal key As String) Me.Key = key End Sub Public Overrides Function ToString() As String Return Me.Key End Function End Class And then I populate the list as:
Dim recognitionList As New List(Of XMLBrandRecognitionNode) recognitionList.Add(XMLTypeN.xml1) recognitionList.Add(XMLTypeN.xml2) recognitionList.Add(XMLTypeN.xml3) Now the part to classify the file (xml1,xml2,xml3)
Dim m_xmld As XmlDocument m_xmld = New XmlDocument() m_xmld.Load("myXML.xml") However I do not know the best way to classify the type, I was thinking on doing a loop and based on the list of nodes that I get return the type
For Each o As XMLBrandRecognitionNode In recognitionList Try child_nodes = m_xmld.GetElementsByTagName(o.ToString) 'maybe a condition or something... Catch ex As Exception Continue For End Try Next What would be the correct way to reckon a xml file type?
No comments:
Post a Comment