|
-
May 22nd, 2012, 10:35 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to identify an xml empty tag using the XmlNodeType object?
Hi,
I have a program that analyzes and processes a complex xml data source (without a schema). The initial part of the program reads the xml line by line and captures the data value, table name and field name for further processing. The data (xml file) is created using InfoPath. This worked fine until we started using InfoPath 2010, which uses the "empty tag" (<tag />) for empty values instead of the traditional tags with no value (<tag></tag>). Of course my program does not know what to do with the empty tags and just ignores them - no exception, and no error.
My question is: Does anyone know how to identify the empty tag using the XmlNodeType object attributes (in blue)?
Thanks for your help and the code is below.
Code:
Private Sub Process_ReportData(ByVal vFilePath As String, ByVal vFileName As String)
' Create an instance of XmlTextReader and call Read method to read the(file)
Dim RecordsTableAdapter As New RecordsTableAdapter
Dim ReportsTableAdapter As New ReportsTableAdapter
Dim textReader As XmlTextReader
Dim vTableName As String = ""
Dim vFieldName As String = ""
Dim vElementMode As String = ""
Dim vValue As String = ""
Dim vDivMode As Boolean = False
Dim vFieldMode As Boolean = False
Dim vElementType As String = ""
Dim vElementName As String = ""
Dim vProjectNo As String = ""
Try
textReader = New XmlTextReader(vFilePath & vFileName)
' Check if an existing record exists. CheckIfRecordExists() willprovide user feedback
If CheckIfRecordExists(vFileName) Then
' Record already exists. Skip this file and notify the user.
NewLineToTextBox("ALERT: Data from " & vFileName & " has already been uploaded and cannot be processed again!", True)
Else
' No existing records were found, continue upload process
' Delete all records from Records
RecordsTableAdapter.DELETE_Records_All()
' Read current XML file name into Records table
RecordsTableAdapter.INSERT_Records("Reports", "XMLfileName", vFileName)
' Process records in Records table
While textReader.Read()
vElementName = textReader.Name
'NewLineToTextBox(XmlNodeType.Element.ToString & ">" & vElementName & ">" ProcessElementName(vElementName, "Action"))
Select Case textReader.NodeType
Case XmlNodeType.Element
'Case "starting" Element
vElementMode = ProcessElementName(vElementName, "Action")
Select Case vElementMode
Case "Field"
vFieldMode = True
vTableName = ProcessElementName(vElementName, "Table")
vFieldName = ProcessElementName(vElementName, "Field")
Case "divMode"
vDivMode = True
End Select
Case XmlNodeType.Text
If vFieldMode And textReader.HasValue Then
If vDivMode Then
vValue = vValue & " ~ " & textReader.Value
Else
' If the field name is a picture field
vValue = textReader.Value
End If
End If
Case XmlNodeType.EndElement
' Process the data and reset the variables
If ProcessElementName(vElementName, "Field") = vFieldName Then
RecordsTableAdapter.INSERT_Records(vTableName, vFieldName, vValue)
'TransferAllData(vTableName, vFieldName, vValue)
vFieldName = ""
vValue = ""
vFieldMode = False
vDivMode = False
End If
End Select
End While
RecordsTableAdapter.Dispose()
End If
Catch Ex As XmlException
NewLineToTextBox("ERROR 001: " & Ex.ToString, True)
End Try
End Sub

As I stand here, on the fringes of my understanding, and look out over the
vast void before me, I realize all that lies ahead: The rest of Dot.Net. . .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|