• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Getting required attributes to output using Transformer Class

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
probably you will have to read everything what I have written, you might understand my question
 
Paul Clapham
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic