HTML conversion for RDF from xml.
This commit is contained in:
parent
3c0519cc22
commit
2058006d34
1 changed files with 31 additions and 4 deletions
|
@ -1,5 +1,16 @@
|
|||
package writer2latex.rdf;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -78,15 +89,31 @@ public class DocumentPart {
|
|||
Element excerptContentNode = excerptDoc.getContentNode();
|
||||
StringBuilder bodyBuilder;
|
||||
Document document = excerptContentNode.getOwnerDocument();
|
||||
DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
|
||||
LSSerializer serializer = domImplLS.createLSSerializer();
|
||||
serializer.getDomConfig().setParameter("xml-declaration", false);
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = null;
|
||||
try {
|
||||
transformer = transformerFactory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.METHOD, "html");
|
||||
} catch (TransformerConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
bodyBuilder = new StringBuilder();
|
||||
NodeList excerptContentNodes = excerptContentNode.getChildNodes();
|
||||
int i = 0;
|
||||
while (excerptContentNodes.getLength() > i) {
|
||||
Node child = excerptContentNodes.item(i);
|
||||
bodyBuilder.append(serializer.writeToString(child));
|
||||
DOMSource source = new DOMSource(child);
|
||||
StringWriter sw = new StringWriter();
|
||||
Result streamResult = new StreamResult(sw);
|
||||
try {
|
||||
transformer.transform(source, streamResult );
|
||||
} catch (TransformerException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
bodyBuilder.append(sw.toString());
|
||||
i++;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue