I thought the 2 numbers in the parentheses were line number and position on the line, but often the position doesn't even exist on the line.Īlso, this may sound ridiculous, but how do you count the lines? Starting with the very first line in the XML file? Or the first line holding data? Do you count blank lines?Īnd, some of the times when I view the XML file in my browser or XML Notepad, there is no indication there is anything wrong with the file. What I am asking is how to decode this error message myself. I have read many posts about this same issue, but all the people post their code and XML file and get an answer like "field X is in the wrong format" or something very specific like that. In several instances I get the error: There is an error in XML document (12,34). I am working on an application that reads an XML file sent to me by a user. My MSDN profile but will not answer coding question on either. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. MessageBox.Show($"Name: ", splitUri(splitUri.Length - 1))įor Each ele As XElement In po.DescendantsAndSelf()Ĭonsole.WriteLine(ele.Ancestors().Count())Ĭonsole.WriteLine(CType(ele, IXmlLineInfo).LineNumber)Ĭonsole.WriteLine(CType(ele, IXmlLineInfo).LinePosition) Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Clickĭim doc = XDocument.Load(fileName, LoadOptions.SetLineInfo) Private fileName As String = IO.Path.Combine(, "Customers.xml") You could try loading the xml document with XDocument overload for line information.Įxample where the document is in the same folder as the app executable. Just to be especially sure (something would have to be really wrong here to need this):ĭim testForNode As XElement = patientInfo.FirstOrDefault Then in code, I test the value of it:ĭim patientInfo As XElement = xDoc.FirstOrDefault You can see there that I added an empty node. What I need is guidance on how to easily find the errors in the XML files I am sent when there is nothing obvious in looking at them, but the program throws the error " ThereĪs an example, I changed your XML as shown below: However, since I am going to be receiving the XML files from users outside our company, I know that I will get ones with mistakes from time to time. The last time I got that error message it was because one of the fields was empty. PSD = CType(xs.Deserialize(reader), Batch) This is the statement I use to read the file. because it teaches you how to think." (Steve Jobs) "Everybody in this country should learn how to program a computer. If there's more than one, there's a better way to do it, but either way I hope that might give you an idea. When it gets to "Stop", hover your mouse over the variables and you'll see the value. ()ĭim xPath As String = IO.Path.Combine(desktopPath, "Example.xml")ĭim xDoc As XElement = XElement.Load(xFI.FullName)ĭim batch As XElement = xDoc.FirstOrDefaultĭim batchDateTime As DateTime = CDate(batch.Value)ĭim requisitionCount As Integer = CInt(batch.Value)ĭim userFieldCount As Integer = CInt(batch.Value) Private Sub Form1_Load(sender As System.Object, _ For example, I put the XML as a file on my desktop and used the following: You might want to consider using LINQ-To-XML.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |