org.w3c.dom.Document.getXmlVersion()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.w3c.dom.Document.getXmlVersion()方法的一些代码示例,展示了Document.getXmlVersion()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Document.getXmlVersion()方法的具体详情如下:
包路径:org.w3c.dom.Document
类名称:Document
方法名:getXmlVersion

Document.getXmlVersion介绍

[英]An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the "XML" feature, the value is "1.0". If this document does not support the "XML" feature, the value is always null. Changing this attribute will affect methods that check for invalid characters in XML names. Application should invoke Document.normalizeDocument() in order to check for invalid characters in the Nodes that are already part of this Document.
DOM applications may use the DOMImplementation.hasFeature(feature, version) method with parameter values "XMLVersion" and "1.0" (respectively) to determine if an implementation supports [XML 1.0]. DOM applications may use the same method with parameter values "XMLVersion" and "1.1" (respectively) to determine if an implementation supports [XML 1.1]. In both cases, in order to support XML, an implementation must also support the "XML" feature defined in this specification. Document objects supporting a version of the "XMLVersion" feature must not raise a NOT_SUPPORTED_ERR exception for the same version number when using Document.xmlVersion.
[中]一种属性,作为XML declaration的一部分,指定此文档的版本号。如果没有声明并且此文档支持“XML”功能,则值为"1.0"。如果此文档不支持“XML”功能,则值始终为null。更改此属性将影响检查XML名称中无效字符的方法。应用程序应调用Document.normalizeDocument()以检查Nodes中已属于此Document的无效字符。
DOM应用程序可以使用参数值分别为“XMLVersion”和“1.0”的DOMImplementation.hasFeature(feature, version)方法来确定实现是否支持[XML 1.0]。DOM应用程序可以使用参数值分别为“XMLVersion”和“1.1”的相同方法来确定实现是否支持[XML 1.1]。在这两种情况下,为了支持XML,实现还必须支持本规范中定义的“XML”特性。使用Document.xmlVersion时,支持“XMLVersion”功能版本的Document对象不得对同一版本号引发NOT_SUPPORTED_ERR异常。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

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);
  }
}

代码示例来源:origin: simpligility/android-maven-plugin

/**
 * 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 );
  }
}

代码示例来源:origin: robovm/robovm

return doc.getXmlVersion();

代码示例来源:origin: plutext/docx4j

return doc.getXmlVersion();

代码示例来源:origin: simpligility/android-maven-plugin

if ( doc.getXmlEncoding() != null && doc.getXmlVersion() != null )
      doc.getXmlVersion(), doc.getXmlEncoding() );

代码示例来源:origin: checkstyle/checkstyle

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);
}

代码示例来源:origin: pentaho/pentaho-kettle

+ xmlDocDTD.getXmlVersion() + "' encoding='" + encoding + "'?>\n<!DOCTYPE " + xmlRootnodeDTD
+ " SYSTEM '" + KettleVFS.getFilename( dtdFileObject ) + "'>\n";

代码示例来源:origin: Impetus/Kundera

doc.getXmlVersion();
Element top = doc.getDocumentElement();

代码示例来源:origin: org.swinglabs/swingx-ws

/**
 * @inheritDoc
 */
public String getXmlVersion() {
  return dom.getXmlVersion();
}

代码示例来源:origin: org.opensingular/singular-commons

@Override
public String getXmlVersion() {
  return original_.getXmlVersion();
}

代码示例来源:origin: org.opensingular/form-core

@Override
public String getXmlVersion() {
  return original_.getXmlVersion();
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

public String getVersion() {
  return dom3 && node != null ? ((Document)node).getXmlVersion() : "1.0";
}

代码示例来源:origin: fbacchella/jrds

/**
 * @return
 * @see org.w3c.dom.Document#getXmlVersion()
 */
public String getXmlVersion() {
  return getParent().getXmlVersion();
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

/**
* 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);
 }
/**

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

/**
  * 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);
}
  /**

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxp-ri

private void setDocumentInfo(Document document) {
  if (!document.getXmlStandalone())
    _handler.setStandalone(Boolean.toString(document.getXmlStandalone()));
  setXMLVersion(document.getXmlVersion());
  setEncoding(document.getXmlEncoding()); 
}

代码示例来源:origin: com.sun.xml.parsers/jaxp-ri

private void setDocumentInfo(Document document) {
  if (!document.getXmlStandalone())
    _handler.setStandalone(Boolean.toString(document.getXmlStandalone()));
  setXMLVersion(document.getXmlVersion());
  setEncoding(document.getXmlEncoding()); 
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

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);
}

代码示例来源:origin: jhannes/eaxy

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;
}

相关文章

微信公众号

最新文章

更多

Document类方法