• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML, check if ITEM exist

 
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, im getting data from XML file, with this way:



(This is just short example)

And my xml file looks like this



What do I want to achieve? As you can see in this example (OF XML File) sometimes I can use item1 or item2 or item3 (or all of them at the same time, doesnt matter) XML ITEMS.

And I can not find way to make code which will check name of each item and lets say check if name of this item is inside List<String> and if is, and its name equals for example item1 do some action and so on with other possible used items.

Thanks in advance for help!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I have to say that's a bad design for an XML document -- hiding data in attribute names shouldn't be done. However if you're stuck with that design, i.e. if somebody else thought it up and won't change it, then you can cast an element node to Element. This interface has a method for getting you all of the attributes, and you can scan through them.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for answer.

I can get attribues like this:



but I can not iterate.

//edit, I found this way to iterate over this map:



It works, but do you think it will be ok like this?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mathew Mintalm wrote:It works, but do you think it will be ok like this?



I don't know. What do you mean by "ok"? It already produces the information you need, so why isn't that already "ok"?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't rely on the position of attributes (ie 0,1,or 2 etc) in the "attributesList" - rely on the attribute name. Parsers are not required to respect the order of attributes in an Element.

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic