/**
* This class will handle converting a xinclude+xpointer marked xml file to a normal xml file
* Because of the shortage of the current jdk ,it only support the xPointer with element instead of NCName
*@author cwang58
*@created date: Jun 10, 2013
*/
public
class
XIncludeConverter {
/**
* this method will handle change the XInclude+XPointer marked xml as normal xml
* @param origialXML the original xml which has the xInclude feature
* @return the parsedXML without the xInclude feature
*/
public
static
String convertXInclude2NormalXML(String originalXML)
throws
SAXException,ParserConfigurationException,TransformerConfigurationException,IOException,TransformerException{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(
true
);
factory.setXIncludeAware(
true
);
factory.setIgnoringComments(
true
);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
Document doc = docBuilder.parse(
new
InputSource(
new
ByteArrayInputStream(originalXML.getBytes(
"utf-8"
))));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT,
"yes"
);
StreamResult result =
new
StreamResult(
new
StringWriter());
DOMSource source =
new
DOMSource(doc);
transformer.transform(source, result);
return
result.getWriter().toString();
}