How to handle XML anomalies!

  • Thread starter Thread starter Bill Nguyen
  • Start date Start date
B

Bill Nguyen

The following XML has an empty <UserDefinedTag />
My VB.NET app got stuck here because I don't know how to handle it. It works
fine with a vlid user defined tag (next record)

<UserDefinedTag>40320121</UserDefinedTag>

Your help is greatly apprecited!!

Bill





- <JACOData>
- <Inventorys>
- <Inventory Type="Physical">
<Product>Dyed Diesel</Product>
<TankNumber>15008230383-1</TankNumber>
<UserDefinedTag />
<DateTime>1/14/2007 1:00:49 PM</DateTime>
<Volume>308.122</Volume>
<Ullage>2674.88</Ullage>
<Height>12</Height>
<WaterHeight>3.4</WaterHeight>
<DaystoEmpty>1</DaystoEmpty>
</Inventory>

- <Inventory Type="Physical">
<Product>Clear Diesel</Product>
<TankNumber>15008230411-1</TankNumber>
<UserDefinedTag>40320121</UserDefinedTag>
<DateTime>1/14/2007 12:00:49 PM</DateTime>
<Volume>308.122</Volume>
<Ullage>5805.88</Ullage>
<Height>12</Height>
<WaterHeight>-9.44</WaterHeight>
<DaystoEmpty>0</DaystoEmpty>
</Inventory>
- </Inventory>
</Inventorys>
</JACOData>
 
Bill said:
The following XML has an empty <UserDefinedTag />
My VB.NET app got stuck here because I don't know how to handle it. It works
fine with a vlid user defined tag (next record)

<UserDefinedTag>40320121</UserDefinedTag>

Well what exactly does your app with that XML? What goes wrong, do you
get a runtime error? How exactly does your code look?

An empty element is perfectly well-formed XML so the XML parser should
not give any problems.
 
Martin;
The problem is that it doesn't throw any error!
I only want to detect if an element is empty.

Here's the code:

DS.ReadXml(mXMLfile)

Dim xRow As DataRow

Dim malternateID, mDaystoEmpty As Integer

For i = 0 To DS.Tables(1).Rows.Count - 1

malternateID = 0

If IsDBNull(DS.Tables(1).Rows(i).Item("UserDefinedTag")) = False Then

malternateID = DS.Tables(1).Rows(i).Item("UserDefinedTag")

Else

MsgBox("invalid altID!: " & mtankID)

End If



Thanks



Bill
 
Bill said:
The problem is that it doesn't throw any error!
I only want to detect if an element is empty.

Do you have a schema associated with the XML? An empty element is not an
error in terms of XML and for instance if the type of the element is
xs:string then in case of the empty element the element is not null but
rather contains the emtpy string.
What you can do is use xsi:nil as a special attribute in XML markup e.g.
<UserDefinedTag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true"/>
but then the schema needs to defined that the element is nillable.
 
Back
Top