1

This is my not well formed XML and i dont have any chance to edit it. I just need to parse it. I tried jackson but its throwing me error.

<root>
  <parent> Some text
      <child>
      </child>
  </parent>

</root>

Any other solution?

Joseph Move
  • 69
  • 1
  • 9
  • I think besides either fixing the xml or writing your own parser you don't have too many choices. Why is the xml malformed in the first place? – Ben Feb 27 '18 at 06:28
  • Possible duplicate of [How to parse invalid (bad / not well-formed) XML?](https://stackoverflow.com/questions/44765194/how-to-parse-invalid-bad-not-well-formed-xml) – Ben Feb 27 '18 at 06:29
  • @Ben its an AIML file... i dont have choice to fixt it.. – Joseph Move Feb 27 '18 at 06:49
  • While I understand where you are coming from the issue is to be honest quite simple: You have something that `resembles` XML but really is not XML. The problem I personally see here is that when you can't expect well formed XML you also can not expect malformed XML in the specific way you have right now. As suggested in the other question linked you should first try to get a grab of well formed xml. If that does not work try "repairing" it. And if that does not work write your own parser basically. – Ben Feb 27 '18 at 07:34
  • (And I know that's a frustrating answer to get but if a file format has a set definition and someone sends you a file claiming it is of that format while not fulfilling the definition... then it just is not the format and you can't parse it with something that is made to... parse the format. It's like giving you a math formula `a (= b + c)` and expecting you to be able to solve it.) – Ben Feb 27 '18 at 07:35
  • @Ben and JosephMove Why do you call this XML malformed? I don't see any problems with well-formedness and a couple of online validators I've tried did not report any problems. – lexicore Feb 27 '18 at 08:51
  • As I see it, this *is* well-formed XML. So any XML parser should be able to parse it. Even JAXB should be able to process it (with `@XmlValue` for text content). – lexicore Feb 27 '18 at 08:53
  • 1
    @lexicore You are... correct. I am honest, I misread the xml there really badly. Parent just has an element node and a text node as a child, I thought it read `` for some weird reason. Okay. @JosephMove sorry for the "advice" which really wasn't any. Every xml parser should be totally fine with parsing this... My apologies. – Ben Feb 27 '18 at 09:16
  • Hello @lexicore. but how can i parse it using jackson? Ben it should be fine. thanks for the help. – Joseph Move Feb 27 '18 at 10:28
  • It's a currently [open](https://github.com/FasterXML/jackson-dataformat-xml/issues/226) issue with Jackson xml parsing – Manos Nikolaidis Feb 27 '18 at 13:06
  • Also please add in the question error messages you are getting in the future – Manos Nikolaidis Feb 27 '18 at 13:07
  • @JosephMove I'm not a Jackson guy, I'm with JAXB. :) Anyway you should post your code as well as errors/exceptions you're getting. – lexicore Feb 27 '18 at 15:56
  • @JosephMove Why do you want to parse XML specifically with Jackson? – lexicore Feb 27 '18 at 15:57

0 Answers0