aspose file tools*
The moose likes XML and Related Technologies and the fly likes using theTags from an XML File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "using theTags from an XML File" Watch "using theTags from an XML File" New topic
Author

using theTags from an XML File

Wolfgang Obi
Ranch Hand

Joined: Dec 05, 2005
Posts: 134
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
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

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

Joined: Dec 05, 2005
Posts: 134
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

Joined: Dec 05, 2005
Posts: 134
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
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

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

Joined: Dec 05, 2005
Posts: 134
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using theTags from an XML File
 
Similar Threads
making XML Doc from JDBC Results
Castor Mapping
iText problem with html-table to pdf
Ajax Jqery xml response - not able to read response
Pronounciation of "Buzz Words"