×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Exception's data, numeric values shown as 0

Exception's data, numeric values shown as 0

Exception's data, numeric values shown as 0

(OP)
Colleagues,
Here's the code:

CODE --> .NET

Try
   Do While loXMLReader.Read()
' 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.

What am I doing wrong?
TIA!

Regards,

Ilya

RE: Exception's data, numeric values shown as 0

How are you creating loXMLReader?

RE: Exception's data, numeric values shown as 0

(OP)
To strongm:

CODE --> .NET

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

RE: Exception's data, numeric values shown as 0

Yep, can't really see anything wrong with that. Think we might need to see your XML file ...

RE: Exception's data, numeric values shown as 0

(OP)
NO-CAN-DO, Sir! sad
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 https://docs.microsoft.com/en-us/dotnet/api/system... is "kinda" brief,
and https://stackoverflow.com/questions/621059/current... is kinda foggy for this illiterate one...)
TIA!

Regards,

Ilya

RE: Exception's data, numeric values shown as 0

(OP)
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):

Well, live and learn every day!

Now I know how to proceed with this code!

Regards,

Ilya

RE: Exception's data, numeric values shown as 0

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

CODE

Dim loXMLReader As XmlReader = XmlReader.Create(tcFileIn, loXMLReaderSettings)
 

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 --> XMLfile

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 <html xmlns="http://www.w3.org/1999/xhtml"> 
<PurchaseOrder>  
  <billTo><street>123 Main St.</street></billTo>  
  <shipTo><street>123 Main St.</street></shipTo>  
</PurchaseOrder>
</html> 

RE: Exception's data, numeric values shown as 0

(OP)
"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! smile
Well, it's Friday-after-lunch (or TGIF, if you prefer), so - HANW everybody! wavey

Regards,

Ilya

RE: Exception's data, numeric values shown as 0

>Yes, I have figured it out already

Yep, hadn't seen your 20:09 post when I wrote mine. Glad you made progress.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close