|
Lines 15-20
Link Here
|
| 15 |
import java.nio.charset.Charset; |
15 |
import java.nio.charset.Charset; |
| 16 |
|
16 |
|
| 17 |
import javax.xml.parsers.DocumentBuilderFactory; |
17 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
18 |
import javax.xml.parsers.SAXParser; |
| 19 |
import javax.xml.parsers.SAXParserFactory; |
| 18 |
import javax.xml.transform.OutputKeys; |
20 |
import javax.xml.transform.OutputKeys; |
| 19 |
import javax.xml.transform.Transformer; |
21 |
import javax.xml.transform.Transformer; |
| 20 |
import javax.xml.transform.TransformerConfigurationException; |
22 |
import javax.xml.transform.TransformerConfigurationException; |
|
Lines 29-34
Link Here
|
| 29 |
import org.w3c.dom.DocumentType; |
31 |
import org.w3c.dom.DocumentType; |
| 30 |
import org.w3c.dom.Node; |
32 |
import org.w3c.dom.Node; |
| 31 |
import org.xml.sax.InputSource; |
33 |
import org.xml.sax.InputSource; |
|
|
34 |
import org.xml.sax.SAXException; |
| 35 |
import org.xml.sax.helpers.DefaultHandler; |
| 32 |
|
36 |
|
| 33 |
/********************************************************************** |
37 |
/********************************************************************** |
| 34 |
* Copyright (c) 2005, 2006 IBM Corporation and others. |
38 |
* Copyright (c) 2005, 2006 IBM Corporation and others. |
|
Lines 1099-1104
Link Here
|
| 1099 |
} |
1103 |
} |
| 1100 |
|
1104 |
|
| 1101 |
/** |
1105 |
/** |
|
|
1106 |
* |
| 1107 |
* Verifies if the specified XML fragment is valid wrt the syntax. |
| 1108 |
* |
| 1109 |
* @param string The string to be normalized. |
| 1110 |
* @return "true" is the specified string is a valid XML fragment, "false" otherwise. |
| 1111 |
*/ |
| 1112 |
|
| 1113 |
public static boolean isValidXML(String xml) |
| 1114 |
{ |
| 1115 |
StringReader xmlStream = new StringReader(xml); |
| 1116 |
SAXParserFactory factory = SAXParserFactory.newInstance(); |
| 1117 |
try { |
| 1118 |
SAXParser saxParser = factory.newSAXParser(); |
| 1119 |
InputSource source = new InputSource(xmlStream); |
| 1120 |
saxParser.parse(source, new DefaultHandler()); |
| 1121 |
} catch (Throwable t) { |
| 1122 |
return false; |
| 1123 |
} finally { |
| 1124 |
if (xmlStream != null) { |
| 1125 |
xmlStream.close(); |
| 1126 |
} |
| 1127 |
} |
| 1128 |
return true; |
| 1129 |
} |
| 1130 |
|
| 1131 |
/** |
| 1102 |
* Normalizes the parameter string according to the XML specification for |
1132 |
* Normalizes the parameter string according to the XML specification for |
| 1103 |
* attribute-value normalization |
1133 |
* attribute-value normalization |
| 1104 |
* (<a href="http://www.w3.org/TR/REC-xml">http://www.w3.org/TR/REC-xml</a>) |
1134 |
* (<a href="http://www.w3.org/TR/REC-xml">http://www.w3.org/TR/REC-xml</a>) |