-1

I have an XML with attributes and elements/tags. I want to know whether using an attribute or a tag is good according to performance.

Could you please give an example to compare if the content has a child tag and also if the content has a attribute. My question is, is it possible to compare 2 attributes with same name in 2 different XML files and also here we will have huge data. So, I want to be sure how the performance is, if i consider it as a attribute or tag.

    <A Name="HRMS">
    <B BName="IN">
    <C Code="0001">
      <IN irec="200" />
      <OUT orec="230" Number="" Outname=""/>
    </C>
    <C Code="0004">
      <IN irec="209" />
      <OUT orec="209" Number="" Outname=""/>
    </C>
    <C Code="0008">
      <IN irec="250" />
      <OUT orec="250" Number="" Outname=""/>
    </C>
    </B>
</A>

Here, i have to compare irec with orec for a particular B name and C code

swetha
  • 449
  • 7
  • 20

1 Answers1

0

It's possible. You need a java lib like jsoup to help parse xml by path expression like jquery css selection expression.

Jsoup is a HTML parser, but html is a kind of xml application, so you can use it to parse xml content.

jsoup example:

String xml = "<root><person name=\"Bob\"><age>20</age></person></root>";
Document root = Jsoup.parse(xml);
System.out.println(root.body().html());//origin XML content
Elements persons = root.getElementsByTag("person");
Element person = persons.first();
System.out.println("The attribute 'name' of Person:" + person.attr("name"));
System.out.println(persons.select("person[name=Bob]").first().text());

You can implement compare difference function using jsoup simplily.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Edited the question. Instead of using Jsoup,I used DOM and i can able to retrieve attributes and I'm able to compare attributes but the problem is, for that particular B name and C code am not able to compare. – swetha Jun 10 '15 at 09:26