Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exception's data, numeric values shown as 0

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
568
US
Colleagues,
Here's the code:

Code:
Try
   Do While loXMLReader.Read()
[indent][/indent]' some code
   Loop 'While loXMLReader.Read()
Catch loErr As XmlException
   MsgBox("Error on line #" & loErr.LineNumber.ToString() & ", pos. #" & loErr.LinePosition.ToString() & vbCrLf & "occurred:" & _
         vbCrLf & loErr.Message & vbCrLf & "when reading file" & vbCrLf & loErr.SourceUri)
   llGoOn = False
End Try

These two numerics, line number and line position always displayed as zero.
20200319_loErr_XmlException_Shows_Zeros_fiptbo.jpg

What am I doing wrong?
TIA!

Regards,

Ilya
 
To strongm:
Code:
loStreamReader = New StreamReader(tcFileIn)

Dim loXMLReaderSettings As New XmlReaderSettings
Dim loXMLReader As XmlReader = XmlReader.Create(loStreamReader, loXMLReaderSettings)

With loXMLReaderSettings
   .CloseInput = False
   .IgnoreComments = True
   .IgnoreWhitespace = False ' True
   .ConformanceLevel = ConformanceLevel.Auto
End With
The XML file it's reading may indeed have "invalid elements", and I need to know which ones they are.

Regards,

Ilya
 
Yep, can't really see anything wrong with that. Think we might need to see your XML file ...
 
NO-CAN-DO, Sir! :-(
T's a real, "live" data. I could've "obfuscate" it, but methinks it's not worth the effort.
The question was (and is): why XmlException shows line and position number as Zeros.
So, lemme dig down deeper:

What is that line and position numbers that XmlException is suppose to show, line and position in the program, or line and position in the read XML file?

(The description on the page is "kinda" brief,
and is kinda foggy for this illiterate one...)
TIA!

Regards,

Ilya
 
Holly-molly!
Look what I've found!
When I changed (see the post #2, from me, on 20 Mar 2020 @ 13:25 - not sure about the time stamp) the .ConformanceLevel = ConformanceLevel.Auto to .ConformanceLevel = ConformanceLevel.Fragment
I got totally different error message (this time with non-zero numerics and with comprehensive text):
20200320_loErr_XmlException_Shows_Erring_Line_In_XML_With_Conformance_Fragment_amyfub.jpg

Well, live and learn every day!

Now I know how to proceed with this code!

Regards,

Ilya
 
Well, the only thing I can suggest is that you create the XXMLReader from a file rather than indirectly via a Stream.

Code:
[blue]Dim loXMLReader As XmlReader = XmlReader.Create(tcFileIn, loXMLReaderSettings)
[/blue]

But I don't hold out much hope this will fix things; there are a number of error conditions that result in no line or position info being provided, and they (not suprisingly) result from the specific format of the XML being read. For example, the XML file below wu=illl casue your code to throw an exception with Line and Position of 0 - but with a somewhat more descriptive error message concerning the use of DTDs (which can be fixed through the XMLReaderSettings (which, by the way, your code is not applying, as you need to have set the settings before you create the XMLReader ...)

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL] 
 <html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL] 
<PurchaseOrder>  
  <billTo><street>123 Main St.</street></billTo>  
  <shipTo><street>123 Main St.</street></shipTo>  
</PurchaseOrder>
</html>
 
you need to have set the settings before you create the XMLReader"
Yes, I have figured it out already, colleague, but thank you anyway. T's already adjusted in my code.
And - yes, ReadElementContentAsString() won't read that node on line 4 coz it does have "children".
Well, it feels like I am to learn using XmlNode.HasChildNodes property! :)
Well, it's Friday-after-lunch (or TGIF, if you prefer), so - HANW everybody! [wavey]

Regards,

Ilya
 
>Yes, I have figured it out already

Yep, hadn't seen your 20:09 post when I wrote mine. Glad you made progress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top