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
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply 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: 78
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: 16483
    
    2

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: 78
probably you will have to read everything what I have written, you might understand my question
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Getting required attributes to output using Transformer Class
 
Similar Threads
xsl transform SystemId UnKnown
Validate XML Document
Looking for some opinions on how to write effective XML
Retrieve objects from XSL transform
Style sheet using Transform