* org.apache.flex.forks.batik.script.Window#parseXML(String,Document)}.
*/
public Node parseXML(String text, Document doc) {
// System.err.println("Text: " + text);
// Try and parse it as an SVGDocument
SAXSVGDocumentFactory df = new SAXSVGDocumentFactory
(XMLResourceDescriptor.getXMLParserClassName());
URL urlObj = null;
if ((doc != null) && (doc instanceof SVGOMDocument))
urlObj = ((SVGOMDocument)doc).getURLObject();
if (urlObj == null) {
urlObj = ((SVGOMDocument)bridgeContext.getDocument()).
getURLObject();
}
String uri = (urlObj==null)?"":urlObj.toString();
try {
Document d = df.createDocument(uri, new StringReader(text));
if (doc == null)
return d;
Node result = doc.createDocumentFragment();
result.appendChild(doc.importNode(d.getDocumentElement(),
true));
return result;
} catch (Exception ex) {
/* nothing */
}
if ((doc != null) && (doc instanceof SVGOMDocument)) {
// Try and parse with an 'svg' element wrapper - for
// things like '<rect ../>' - ensure that rect ends up
// in SVG namespace - xlink namespace is declared etc...
// Only do this when generating a doc fragment, since
// a 'rect' element can not be root of SVG Document
// (only an svg element can be).
StringBuffer sb = new StringBuffer(FRAGMENT_PREFIX.length() +
text.length() +
FRAGMENT_SUFFIX.length());
sb.append(FRAGMENT_PREFIX);
sb.append(text);
sb.append(FRAGMENT_SUFFIX);
String newText = sb.toString();
try {
Document d = df.createDocument
(uri, new StringReader(newText));
// No document given so make doc fragment from our
// new Document.
if (doc == null) doc = d;
for (Node n = d.getDocumentElement().getFirstChild();