Reputation: 35316
I'm trying to transform an XML into a Markdown
public static Document transformXmlToMarkdown(String xml) throws TransformerException {
Source source = new StreamSource(new StringReader(xml));
TransformerFactory tFactory=TransformerFactory.newInstance();
DOMResult result = new DOMResult();
Transformer transform = tFactory.newTransformer(new StreamSource(new StringReader(markdown)));
transform.transform(source, result);
return (Document) result.getNode();
}
The markdown
in the new StringReader(markdown)
is based here.
The problem with this code is that I does not transform.
The input:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<en-note>
<div>
<br/>
</div>
<div>
<br/>
</div>
<en-media hash="" type="application/octet-stream"/>
<div>
<br/>
</div>
<div>This is my first Evernote blog with image/photo attached.</div>
<div>
<br/>
</div>
<div>This is another line. </div>
<div>
<br/>
</div>
<div>Some
<i>formatting </i>also for
<b>some </b>lines.
</div>
</en-note>
Output should be:
This is my first Evernote blog with image/photo attached.
This is another line.
Some _formatting_ also for **some** lines.
Any hints would be appreciated.
Upvotes: 0
Views: 450
Reputation: 1573
The xslt script you referring to can be used to convert some kind of HTML to Markdown.
Your XML is not HTML. Your XML starts with a root element "en-note" and there is no match on that in the XSLT, so no processing of that element.
Upvotes: 1