From: Scott Purcell [mailto:spurcell(_at_)vertisinc(_dot_)com]
Subject: [xsl] Need Attributes From A InputStream
I am receiving a InputStream which is a XML file. In the xml
file there are some attributes I want to grab, to put into a DB.
Parsing an InputStream or passing an InputStream into an XSLT processor is no
big deal; in the XSLT case:
javax.xml.transform.stream.StreamSource ss = new
javax.xml.transform.stream.StreamSource(<<your input stream here>>);
I would like to grab the "width", "height", "copyright" and
"colorSpace", "transparency", "ditherAlgorithm" which come
from two differrent elements.
Here is one approach:
1) Wrap your InputStream in a StreamSource as above.
2) Write an XSLT stylesheet that converts the input XML document into a set of
SQL statements (e.g., an INSERT statement).
3) Create a StreamResult that wraps a StringWriter.
4) Run the transformation against the StreamSource.
5) Collect the resulting SQL from the StringWriter and execute it against the
target database.
Other approaches include writing your own SAX handler, but the XSLT approach is
the simplest (and most appropriate to the list).
-- Paul
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list