private void writeDocument(Document document, Writer writer) throws IOException { String v = document.getXmlVersion(); writer.append("<?xml "); writer.append(" version='").append(v == null ? "1.0" : v).append("'"); writer.append(" encoding='").append(encoding.name()).append("'"); if (document.getXmlStandalone()) { writer.append(" standalone='yes'"); } writer.append("?>").append(lineSeparator); NodeList nodes = document.getChildNodes(); for (int i = 0, imax = nodes.getLength(); i < imax; ++i) { write(nodes.item(i), writer, 0); } }
/** * Write manifest using JAXP transformer */ private void writeManifest( File manifestFile, Document doc ) throws IOException, TransformerException { TransformerFactory xfactory = TransformerFactory.newInstance(); Transformer xformer = xfactory.newTransformer(); xformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" ); Source source = new DOMSource( doc ); OutputStreamWriter writer = null; try { manifestFile.getParentFile().mkdirs(); String encoding = doc.getXmlEncoding() != null ? doc.getXmlEncoding() : "UTF-8"; writer = new OutputStreamWriter( new FileOutputStream( manifestFile, false ), encoding ); if ( doc.getXmlEncoding() != null && doc.getXmlVersion() != null ) { String xmldecl = String .format( "<?xml version=\"%s\" encoding=\"%s\"?>%n", doc.getXmlVersion(), doc.getXmlEncoding() ); writer.write( xmldecl ); } Result result = new StreamResult( writer ); xformer.transform( source, result ); } finally { IOUtils.closeQuietly( writer ); } }
return doc.getXmlVersion();
return doc.getXmlVersion();
if ( doc.getXmlEncoding() != null && doc.getXmlVersion() != null ) doc.getXmlVersion(), doc.getXmlEncoding() );
protected static void verifyXml(String expectedOutputFile, ByteArrayOutputStream actualOutputStream, BiPredicate<Node, Node> ordered, String... messages) throws Exception { String expectedContents = readFile(expectedOutputFile); for (int i = 0; i < messages.length; i++) { expectedContents = expectedContents.replace("$" + i, messages[i]); } final Document expectedDocument = XmlUtil.getRawXml("audit output", expectedContents, expectedContents); final Document actualDocument = getOutputStreamXml(actualOutputStream); Assert.assertEquals("xml encoding should be the same", expectedDocument.getXmlEncoding(), actualDocument.getXmlEncoding()); Assert.assertEquals("xml version should be the same", expectedDocument.getXmlVersion(), actualDocument.getXmlVersion()); verifyXmlNode(expectedDocument, actualDocument, "/", ordered); }
+ xmlDocDTD.getXmlVersion() + "' encoding='" + encoding + "'?>\n<!DOCTYPE " + xmlRootnodeDTD + " SYSTEM '" + KettleVFS.getFilename( dtdFileObject ) + "'>\n";
doc.getXmlVersion(); Element top = doc.getDocumentElement();
/** * @inheritDoc */ public String getXmlVersion() { return dom.getXmlVersion(); }
@Override public String getXmlVersion() { return original_.getXmlVersion(); }
@Override public String getXmlVersion() { return original_.getXmlVersion(); }
public String getVersion() { return dom3 && node != null ? ((Document)node).getXmlVersion() : "1.0"; }
/** * @return * @see org.w3c.dom.Document#getXmlVersion() */ public String getXmlVersion() { return getParent().getXmlVersion(); }
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = factory.newDocumentBuilder(); Document document = documentBuilder.parse(new File("myFile.xml")); String version = document.getXmlVersion(); String encoding = document.getXmlEncoding(); boolean standalone = document.getXmlStandalone();
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; String versionValue; doc = (Document) load("hc_staff", false); versionValue = doc.getXmlVersion(); assertEquals("documentgetxmlversion01", "1.0", versionValue); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; String versionValue; doc = (Document) load("barfoo", false); versionValue = doc.getXmlVersion(); assertEqualsIgnoreCase("documentgetxmlversion03", "1.0", versionValue); } /**
private void setDocumentInfo(Document document) { if (!document.getXmlStandalone()) _handler.setStandalone(Boolean.toString(document.getXmlStandalone())); setXMLVersion(document.getXmlVersion()); setEncoding(document.getXmlEncoding()); }
private void setDocumentInfo(Document document) { if (!document.getXmlStandalone()) _handler.setStandalone(Boolean.toString(document.getXmlStandalone())); setXMLVersion(document.getXmlVersion()); setEncoding(document.getXmlEncoding()); }
protected void setupLocator(Document doc) { LocatorImpl locator = new LocatorImpl(); try { locator.setEncoding(doc.getXmlEncoding()); locator.setXMLVersion(doc.getXmlVersion()); } catch(Exception ex) { //if unable to invoke these methods, just return and don't invoke return; } this.contentHandler.setDocumentLocator(locator); }
public static Document fromDom(org.w3c.dom.Document document) { Document doc = new Document(); if (document.getXmlEncoding() != null) { doc.setEncoding(document.getXmlEncoding()); } doc.setVersion(document.getXmlVersion()); if (document.getDoctype() != null) doc.addDTD(document.getDoctype().getBaseURI()); doc.setRootElement((Element)createNode(document.getDocumentElement())); return doc; }