I'm new to java but making good progress, though still having trouble knowing which api to use for what. I'm trying to extract xml data from a string, the string being the contents of an xml file. I'm trying to use a SAXParser (xerces) but the xmlString below is expecting the url where the xml file is. SAXParser xr = new SAXParser(); xr.setContentHandler( new XmlParser() ); xr.parse(xmlString); Unfortunatly I can't access the url directly from this code. What can I use to parse a string of xml data?
Look at the parse() signatures available on SAXParser. A couple of them take InputStream parameters. Can we turn your String into an InputStream? InputStream docs show a number of subclasses. ByteArrayInputStream can be constructed with a byte and we can turn String into byte. So I'd give it a try with: parse( new ByteArrayInputStream( myString.getBytes() ) ); Hope that helps. (Hope it works!)
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi