Created
July 23, 2021 01:57
-
-
Save blakehurlburt/7f618f2ac1680952b5bb46c6a4412662 to your computer and use it in GitHub Desktop.
TTML XPath example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Main { | |
public static void main(String[] args) throws Exception { | |
XPath xpath = XPathFactory.newInstance().newXPath(); | |
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); | |
Document document = parser.parse(new InputSource(new FileInputStream("ReplaceWithYourTtmlFile.ttml"))); | |
Node metadata = (Node) xpath.compile("/tt/head/metadata").evaluate(document, XPathConstants.NODE); | |
System.out.println(nodeToString(metadata)); | |
} | |
private static String nodeToString(Node node) throws Exception { | |
StringWriter sw = new StringWriter(); | |
Transformer transformer = TransformerFactory.newInstance().newTransformer(); | |
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); | |
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); | |
transformer.transform(new DOMSource(node), new StreamResult(sw)); | |
return sw.toString(); | |
} | |
private Main() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment