wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Digester in XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Digester in XML" Watch "Digester in XML" New topic
Author

Digester in XML

Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
Hi,

Can anyone help me in getting the full implementation details in digester in XML ?

for example I have the following XML:

<root>
<AxisData>
<cellvalue>
86
</cellvalue>
<cellvalue>
56
</cellvalue>
</AxisData>
<AxisInfo>
<cellInfo>
AX
</cellInfo>
<cellInfo>
BX
</cellInfo>
<AxisInfo>
<root>

I need the XML in the following format:

<root>
<AxisInfoData>
<cellInfo>
AX
</cellInfo>
<cellvalue>
86
</cellvalue>
<cellInfo>
BX
</cellInfo>
<cellvalue>
56
</cellvalue>
<AxisInfoData>
<root>


1. How to use the digester ?

2. How to use the XSLT transformation in the Java object which will be created using the digester?

Cheers,
-Biswa


Thanks<br />-Swosti
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Full implementation details? Here: http://jakarta.apache.org/commons/digester/

How to use? That link seems to have examples.

The Java object that Digester creates doesn't contain an XSLT transformation. However if you want to use XSLT to convert the former XML to the latter XML, I don't understand where Digester comes into that picture.
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
Paul,

Will you please help me to get the details of the digester usage ?

We have a few webservices where we can get the XML. We do a transformation using XSLT and show up the data in the web pages. The XML which we get are bit complex and we have to move to and fro to get the transformation done. The performance is poor.

We are thinking of using the Digester to improve the performance ? Will it help us ?


I read and learnt that ,

1) Digester framework is a high-level interface that parses an XML stream and populates the data into Java objects based on rules provided to the Digester component.

Pleas help

Cheers,
-Biswa
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
I can't see how making extra Java objects with digester could speed up your XML data transformation. Have you done any measurements to locate the real bottleneck in the process?

If this was my problem I would look into using XPath expressions to extract the required data from the web service XML document. XPath is built in to Java 1.5 - or you can get it in other libraries.

Bill
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
Thanks.

There are Basically two issues related with the process.

1. The time taken to get the XML is more.
2. The XML format is not given as per our requirement.

So what we thought of

For (1) to cache the Java Objects and refer always when needed, instead of getting it from the webservices always
For (2) to create the digester rules are per our requirement and store the data in the java objects.

Kinldy let me know if the approaches are correct or not.

Cheers,
-Biswa
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
As to #1, caching the data locally vs. getting it fresh from the WS is certainly a good idea. But you can just as well cache an XML document as text or as DOM tree, so thgat is a different question than whether or not to use Digester. Like Bill said, first measure where the actual bottleneck is before you start optimizing.

I'm not sure what you're asking in #2. Is the XML format not the same every time?


Ping & DNS - my free Android networking tools app
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
The point in (#2) can be interpreted in the following manner.

Existing XML:



We want in the following format.


In the second XML, the transformation will be easy in comparision with the first one. I think so. By using the digester we can achieve the second one.Please let me know if I am wrong.

Cheers,
-Biswa
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
Digester is certainly not the right tool for transforming one XML format to another.
Either a Java program to read the existing format and write the new one, or an XSLT script to accomplish the same will do the trick. The program would be faster.
Bill
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
I am not very clear about this. Can you please give a sample program and show it.I would like to share another information that the XML we get is through the web browser.

Cheers,
-Biswa
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
Your question indicates that you are not really familiar with the toolkit that Java provides for manipulating XML. I suggest that you read some tutorials and experiment with simple XML documents before tackling your original problem.
Here is a tutorial dealing with the DOM or Document Object Model manipulation of XML data.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Digester in XML