Parsing all XML files with Xerces J

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssaraceni
    New Member
    • Sep 2008
    • 18

    Parsing all XML files with Xerces J

    Hi, I want to open XML files, also non well formed ones, to show the XML tags into my java application.
    Actually I'm using Xerces2-J to parse XML files, but if I try to open a non-well formed file, the parser throws the SaxException.
    How can I open this files?
    Thanks
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by ssaraceni
    Hi, I want to open XML files, also non well formed ones, to show the XML tags into my java application.
    Actually I'm using Xerces2-J to parse XML files, but if I try to open a non-well formed file, the parser throws the SaxException.
    How can I open this files?
    Thanks
    Well, "non-well formed" xml simply isn't xml. Compare a Java source text that
    contains syntax errors; it isn't Java and there is (almost) nothing you can do
    about it. You can parse the "non-well formed" xml text until it doesn't make sense
    anymore; you even don't know what to do at that point: e.g. insert a correct token
    or adjust the current token or just delete it. "non-well formed" is just a euphemism
    for "it isn't"; it takes a human to decide how to correct that text; computers aren't
    of much help here.

    kind regards,

    Jos

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      If it's some kind of XML viewer or editor you're writing, you'll have to find a way around parsing them with Xerces, just handle them as text files for instance. (You can still try to validate them with Xerces of course.) Then, you'll have to filter and parse the stuff yourself. I can't see any simpler way to solve this, sorry.

      Greetings,
      Nepomuk

      Comment

      Working...