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;
|
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.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -78,15 +89,31 @@ public class DocumentPart {
|
||||||
Element excerptContentNode = excerptDoc.getContentNode();
|
Element excerptContentNode = excerptDoc.getContentNode();
|
||||||
StringBuilder bodyBuilder;
|
StringBuilder bodyBuilder;
|
||||||
Document document = excerptContentNode.getOwnerDocument();
|
Document document = excerptContentNode.getOwnerDocument();
|
||||||
DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
LSSerializer serializer = domImplLS.createLSSerializer();
|
Transformer transformer = null;
|
||||||
serializer.getDomConfig().setParameter("xml-declaration", false);
|
try {
|
||||||
|
transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.METHOD, "html");
|
||||||
|
} catch (TransformerConfigurationException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
bodyBuilder = new StringBuilder();
|
bodyBuilder = new StringBuilder();
|
||||||
NodeList excerptContentNodes = excerptContentNode.getChildNodes();
|
NodeList excerptContentNodes = excerptContentNode.getChildNodes();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (excerptContentNodes.getLength() > i) {
|
while (excerptContentNodes.getLength() > i) {
|
||||||
Node child = excerptContentNodes.item(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++;
|
i++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue