-2

we have a very long XMLResponse from one web service, and we want to optimize the time of parsing this XMLResponse, so the strategy is to parse the XMLResponse line by line until we have what we need from the XMLResponse => the mandatory elements

we know the mandatory elements and we know also that the XMLResponse is valid XML object, so we can stop reading the string before arriving at the end.

so please guys: what are the tools that gonna help us to do this?

thank you in advance ...

chay
  • 1
  • 2
    Maybe XPath helps here? – Seelenvirtuose Sep 20 '19 at 15:15
  • I'd not parse line by line. XML is not line-oriented, and any change in lines will break your code. If you want to save memory, look into SAX XML parsing, where you only deal with one element at a time, as opposed to DOM parsing, which keeps the whole XML in memory. – Robert Sep 20 '19 at 15:36

2 Answers2

-1

Using the Stax api is probably the most efficient way of parsing xml since the calling code is in complete control and can skip whole element subtrees that are not needed.

There is a good tutorial about this approach at https://medium.com/tech-travelstart/efficient-xml-parsing-with-java-df3169e1766b

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
-1

I would not advise to parse an XML by hand. You either parse it accurately, (which would be as time consuming as parsing it with a parser) or you do it approximately risking errors.

If you need performance you can use a SAX parser, it get's more complicated but it is as fast as it can be.

minus
  • 2,646
  • 15
  • 18