• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using theTags from an XML File

 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
does anyone know a method which can be used to identify and filter out the tags in an XML document for further use ?

thank you

-W.O.
 
Paul Clapham
Sheriff
Pie
Posts: 20735
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There really isn't a reliable way. The main problem is that parsers won't distinguish between an empty-element tag <empty/> and a pair of tags with no content <empty></empty>.

Why do you need to identify the tags, anyway?
 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks paul,...

I'm trying to create a table (e.g. with Jface) where the tags are the column names and the elements with identical tags fill out the the columns.....

any tips?
 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i found a method: "getTagName()"

however for some strange reason i found it only in the old API (java 1.4.2)

and even more important: only for DOM,.... [---> org.w3c.dom.Node]

is there a method like this in the current API?....

and maybe for the SAX parser?....

worst case would mean using DOM,....but where is the method hiding (if still available) in the current API...i.e.: at least java 5?

thanks
[ September 20, 2007: Message edited by: Wolfgang Obi ]
 
Paul Clapham
Sheriff
Pie
Posts: 20735
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wolfgang Obi:
I'm trying to create a table (e.g. with Jface) where the tags are the column names and the elements with identical tags fill out the the columns.....

any tips?
Translating that into standard XML terminology: you are trying to create a table where the element names are the column names and (something that I don't understand) goes into the column cells.

So you don't need to get the tags at all, you need to get the element names. The SAX parser gives you those in your startElement() method, if you're using a SAX parser. As for the rest of your requirements, perhaps it's the text between the tags that you're interested in? In standard XML terminology, that's a text node that is the child of the element node you think of as "the tags". And your SAX parser gives you that in your characters() method.

You could use a DOM parser too, but if you continue to think of "tags" you will have trouble finding the documentation. The DOM parser gives you a tree of nodes; some of the nodes are Element nodes and some are Text nodes. You can write code that navigates that tree and picks out the information you need.
 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
Translating that into standard XML terminology: you are trying to create a table where the element names are the column names and (something that I don't understand) goes into the column cells.

So you don't need to get the tags at all, you need to get the element names. The SAX parser gives you those in your startElement() method, if you're using a SAX parser. As for the rest of your requirements, perhaps it's the text between the tags that you're interested in? In standard XML terminology, that's a text node that is the child of the element node you think of as "the tags". And your SAX parser gives you that in your characters() method.

You could use a DOM parser too, but if you continue to think of "tags" you will have trouble finding the documentation. The DOM parser gives you a tree of nodes; some of the nodes are Element nodes and some are Text nodes. You can write code that navigates that tree and picks out the information you need.



hello paul
thanks for the help.

take this XML file for example:




i am trying to build a table where:
"para" would be a column name, and "Hello World!" would go into a column cell.

I hope i understood correctly:
so, ...
startElement() would give me: "doc" AND/OR "para"
and
characters() would give me: "Hello, world!" ?

-W.O.

[ September 21, 2007: Message edited by: Wolfgang Obi ]
[ September 21, 2007: Message edited by: Wolfgang Obi ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic