N
N
Nikolay Baranenko2017-07-28 10:19:04
Java
Nikolay Baranenko, 2017-07-28 10:19:04

How to select 2 values ​​at once by tag name in one loop?

Hello.
There is this xml

<s:Body>
<GetQualityFulfilmentResponse xmlns="http://schemas.septembers.ru/septic/workflow/quality/services">
<GetQualityFulfilmentResult xmlns:a="http://schemas.dataseptic.org/2004/07/Septic.Quality" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Segments xmlns:b="http://schemas.septembers.ru/septic/flow/quality/types">
<b:QualityRuleFulfilmentSegment>
<b:AcceptedMessagesCount>0</b:AcceptedMessagesCount>
<b:FailedCount>
1
</b:FailedCount>
<b:SentMessagesCount>0</b:SentMessagesCount>
<b:SucceededCount>
123
</b:SucceededCount>
<b:TimeFrom>2017-07-27T16:32:40.737+03:00</b:TimeFrom>
<b:TimeTo>2017-07-27T18:12:40.737+03:00</b:TimeTo>
</b:QualityRuleFulfilmentSegment>
</a:Segments>
</GetQualityFulfilmentResult>
</GetQualityFulfilmentResponse>
</s:Body>

using jsoup to pull out b:FailedCount and b:SucceededCount values
org.jsoup.nodes.Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
        for (org.jsoup.nodes.Element e : doc.getElementsByTag("b:FailedCount")) {
            System.out.println(e.ownText());
        }
        for (org.jsoup.nodes.Element e : doc.getElementsByTag("b:SucceededCount")) {
            System.out.println(e.ownText());
        }

how to select 2 values ​​at once by tag name in one loop?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
protven, 2017-07-28
@drno-reg

Elements result = doc.getElementsByTag("b:FailedCount");
        result.addAll(doc.getElementsByTag("b:SucceededCount"));

And then iterate over result.
PS Always look at what kind of objects you have and what methods they provide. So, Elements is essentially a regular Java ArrayList that you can work with using its standard methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question