1

I'm very new to XML parsing and don't really know what I'm doing. I'm trying to parse a file in XML, but have encountered this error:

System.Xml.XmlException: ''Element' is an invalid XmlNodeType.'

Here's the code below:

    Dim settings As XmlReaderSettings = New XmlReaderSettings
    settings.DtdProcessing = DtdProcessing.Parse
    Dim xmlR = XmlReader.Create(jmdictpath, settings)

    Do While xmlR.Read()
        If Not xmlR.IsEmptyElement And xmlR.NodeType = XmlNodeType.Element Then
            MsgBox(xmlR.ReadElementContentAsString)
        End If
    Loop

The error runs on the line MsgBox(xmlR.ReadElementContentAsString). I've tested that the element is not empty, so that shouldn't be a problem.

Then I checked the xmlReader object in QuickWatch, and it looks like what the object is currently trying to read is a whitespace or line return character:

enter image description here

Is there some standard method to handle all cases like this when parsing XML so that whitespace characters don't get picked up as XML tags and confuse the reader?

3
  • Have a look at your Not with your And. Are you sure it is evaluating like ((Not first) and second) vs (not(first and second))? Try adding some parens and let us know if it behaves differently. Commented Feb 12, 2020 at 21:11
  • 1
    I think you might be having issues similar to this Try setting the IgnoreWhitespace property to true on XmlReaderSettings Commented Feb 12, 2020 at 21:17
  • @jazakari That seemed to fix the problem, thanks :). I now have a different problem but it's for a different question and some more research on how XML parsing works I guess haha Commented Feb 12, 2020 at 21:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.