Hi,
I'm not sure if this is where I should be asking this.
I'm writing a custom generator that needs to just return an XML document that's contained within a String. Now in the past I have used code like this [Simple Hello-World]:
*
public* *class* SMSGenerator *extends* AbstractGenerator {
AttributesImpl emptyAttr = *new* AttributesImpl();
* public* *void* generate() *throws* SAXException
{
contentHandler.startDocument();
contentHandler.startElement("", "abc", "def", emptyAttr);
contentHandler.characters("Hello World".toCharArray(), 0, "Hello World".length());
contentHandler.endElement("","abc", "def");
contentHandler.endDocument();
}
}
I now have the XML file in a String and I need this to be "returned" by the generator. I was just wondering if anybody knew how to do that without going through the String, breaking it into "Elements" and "characters"
You use a SAX parser, like this:
public void generate() throws SAXException { // ... org.xml.sax.XMLReader xr = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); xr.setContentHandler(this.contentHandler); String result = ...; xr.parse(new org.xml.sax.InputSource(result.getBytes()); }
This should do the trick. You might have to specify the character encoding when converting the String to a byte array with getBytes().
-- Holger Dewes
insiders GmbH Tel. +49 6131 98210-0 Wissensbasierte Systeme Fax +49 6131 98210-11 Wilh.-Th.-Römheld-Str. 18 [EMAIL PROTECTED] 55130 Mainz http://www.insiders.de/
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]