How about: String xmlString = ... InputSource xmlSource = new InputSource(new StringReader(xmlString));
Jim > -----Original Message----- > From: Mark Johnson [mailto:[EMAIL PROTECTED]] > Sent: Friday, February 22, 2002 1:44 PM > To: 'Tomcat Users List' > Subject: RE: Fumbling around Tomcat and Java and XML > > > If I already have the XML in a string how do I create an > InputSource for the > XMLReader to parse: > > String xmlResults = getResults(); > if( xmlResults == null ) > return; > > XMLReader reader = XMLReaderFactory.createXMLReader( > "org.apache.xerces.parsers.SAXParser" ); > ReportFilterContentHandler handler = new ReportFilterContentHandler( > filter ); > reader.setContentHandler( handler ); > InputSource source = new InputSource( xmlResults ); > reader.parse( source ); // exception, File "report-title" not found. > > > The documentation says: > > The SAX parser will use the InputSource object > to determine how to read XML input. If there is > a character stream available, the parser will read > that stream directly; if not, the parser will use > a byte stream, if available; if neither a character > stream nor a byte stream is available, the parser > will attempt to open a URI connection to the resource > identified by the system identifier. > > It sounds as if you give in a String of xml data it will not > attempt to try > to interpret it as a URI but I guess that's not really the case? > > -----Original Message----- > From: Jim Urban [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 21, 2002 2:59 PM > To: Tomcat Users List > Subject: RE: Fumbling around Tomcat and Java and XML > > > Here is a hint to get you started... > > import org.w3c.dom.Attr; > import org.w3c.dom.Document; > import org.w3c.dom.Element; > import org.w3c.dom.NamedNodeMap; > import org.w3c.dom.Node; > import org.w3c.dom.NodeList; > import org.apache.xerces.parsers.DOMParser; > > > DOMParser parser = new DOMParser(); > parser.parse("your.xml"); > Document document = parser.getDocument(); > NodeList elements = > document.getElementsByTagName("your-element-tag"); > int elementCount = elements.getLength(); > for (int i = 0; i < elementCount; i++){ > Element element = (Element) elements.item(i); > ... > > > -----Original Message----- > > From: Mark Johnson [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, February 21, 2002 2:18 PM > > To: 'Tomcat User List (E-mail)' > > Subject: Fumbling around Tomcat and Java and XML > > > > > > ENV: Linux 2.4, tomcat-4.0.1, JDK1.3.1 > > > > I have just inherited a servlet project that uses tomcat > running on Linux. > > I'm not a java programmer so I'm fumbling around trying to > learn java and > > tomcat and everything else that's involved simultaneously. > > > > I need to add the ability to parse an XML document but have not been > > successful at getting to the right jar files. What import > directive do I > > need to use in my servlet to get access to the DOM parsers > > available in the > > tomcat xerces.jar, or what environment settings do I need to check for > > correctness. > > > > I tried "import javax.xml.*;" which said that I had no such > javax.xml does > > not exist, I tried "import org.w3c.dom.*;" and the same general > error. I > > have been browsing the sun java site for a day now and can't figure out > > where to download the javax XML stuff. I found the xerces xml > files but it > > complains about the w3c stuff. I downloaded the w3c stuff but, > > can't get it > > to compile. I'm striking out on all fronts. I noticed that > tomcat already > > has a xerces.jar but I don't know how to get to it or what my > environment > > variables should be setup as and if it's still going to > complain about the > > w3c stuff... > > > > Does the tomcat XML parsing stuff work out of the box or do I need to do > > download more software. From what I've read so far, Sun only > provides an > > interface which must be coupled to a specific vendor's > implementation. I > > assume that is what xerces is -- the actual implementation based > > on the Sun > > interface. But I don't know if everything is all there with a vanilla > > installation of the jdk and tomcat. Is there a way to find out? > > > > Thanks for any direction you can give me here. I can't see to find the > > correct document to read so if you can send me a URL to the any > documents > > that tell me how to set this up that would be great. It can't be > > this hard I > > must be just not understanding something trivial... > > > > thanks for your time... > > > > -- > > To unsubscribe: <mailto:[EMAIL PROTECTED]> > > For additional commands: <mailto:[EMAIL PROTECTED]> > > Troubles with the list: <mailto:[EMAIL PROTECTED]> > > > > > > > -- > To unsubscribe: <mailto:[EMAIL PROTECTED]> > For additional commands: <mailto:[EMAIL PROTECTED]> > Troubles with the list: <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe: <mailto:[EMAIL PROTECTED]> > For additional commands: <mailto:[EMAIL PROTECTED]> > Troubles with the list: <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>
