aspose file tools*
The moose likes XML and Related Technologies and the fly likes Getting required attributes to output using Transformer Class 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 "Getting required attributes to output using Transformer Class" Watch "Getting required attributes to output using Transformer Class" New topic
Author

Getting required attributes to output using Transformer Class

Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 79
Hi
I have a XML file which I read and convert that to a CSV file using the Transformer class. It wirtes the data exaclty but I have to get only specific values from XML based on the inputs.

<Product ModelNumber="A3316ABSBB">
<DataSource Name="SPP">
<Column Name="CARTON_LENGTH">31.3</Column>
<Column Name="PROD_DEPT_NAME">REFRIGERATION</Column>
<Column Name="SUPERSEDED_DATE">1900-01-01</Column>
<Column Name="NET_WEIGHT">144</Column>
<Column Name="SKU_DESCRIPTION">16 cu ft, wire, recessed handl</Column>
<Column Name="WHITE_GOOD">Y</Column>
</Product>
<Product ModelNumber="A3316ABSWW">
<DataSource Name="SPP">
<Column Name="CARTON_LENGTH">31.3</Column>
<Column Name="PROD_DEPT_NAME">REFRIGERATION</Column>
<Column Name="SUPERSEDED_DATE">1900-01-01</Column>
<Column Name="NET_WEIGHT">144</Column>
<Column Name="SKU_DESCRIPTION">16 cu ft, wire, recessed handl</Column>
<Column Name="WHITE_GOOD">Y</Column>
</Product>

Above is my XML file. In this way I will have thousands of attributes, I will have to retireve the data only for specific modelnumbers.

Below is my code which wrks fine and retireves all the models into a CSV file:

TransformerFactory factory = TransformerFactory.newInstance();
StreamSource streamSource = new StreamSource(styleSheetName);
Transformer transformer = factory.newTransformer(streamSource);
XMLReader reader = XMLReaderFactory.createXMLReader();
//sourceXmlReader and xsltResultWriter is passed as an inputstream and outputstream
InputSource sourceReader = new InputSource(sourceXmlReader);
Source source = new SAXSource(reader, sourceReader);
Result result = new StreamResult(xsltResultWriter);
for (String parameterName : this.getParamaters().keySet())
{
transformer.setParameter(parameterName, this.getParamaters().get(parameterName));
}
transformer.transform(source, result);
sourceXmlReader.close();
xsltResultWriter.close();

regards
Prashanth
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

So you have an XML document. And you have some code which works fine. But do you have a question? If so, what is it?
Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 79
probably you will have to read everything what I have written, you might understand my question
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Nope. I read it again and I still don't understand what you want to know. Normally when somebody doesn't understand, it's your responsibility to fix that problem by providing more information. I suggest you try that in this case if you are interested in getting an answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Getting required attributes to output using Transformer Class