domimplementationregistry.getvalue类的getdomimplementation返回null怎么办

拒绝访问 | www. | 百度云加速
请打开cookies.
此网站 (www.) 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(390d9a4b95c043a1-ua98).
重新安装浏览器,或使用别的浏览器本帖子已过去太久远了,不再提供回复功能。Posts - 554,
Articles - 272,
Comments - 1118
号角声在远方又吹响/何时回故乡/又怎么回故乡/曾经的你现在又怎样/是谁的新娘/为谁做衣裳/
火跳动着绝望/谁在低声吟唱/说遗忘者的哀伤 /用战斗证明希望
20:14 by Rollen Holt, ... 阅读,
首先说一下,由于这篇文章主要是自己随性学习写的,所以读者看起来可能很乱,呵呵。可以给大家稍微推荐一篇:&稍微清晰一点
#coding=utf-8
#解析xml文件中的所有的link标签
from xml.dom import minidom
from xml.dom.minidom import getDOMImplementation
doc=minidom.parse("d:\\hello.html")
nodes=doc.getElementsByTagName("link")
for node in nodes:
print "&",node.tagName,
print "type=\"",node.getAttribute("type"),"\"",
print "rel=\"",node.getAttribute("rel"),"\"",
print "href=\"",node.getAttribute("href"),"\"",
print "/&"
print "通过另外一种方式获得link标签"
linknodes=doc.getElementsByTagName("link")
for i in range(len(linknodes)):
print linknodes[i].getAttribute("type"),
print linknodes[i].getAttribute("rel"),
print linknodes[i].getAttribute("href")
node=linknodes[0]
print dir(node)
print node.parentNode
print node.prefix
print node.nodeType,node.nodeValue,node.nodeName
print node.localName
print node.childNodes
print node.firstChild,node.lastChild
print node.attributes
print node.namespaceURI
print node.nextSibling
print "--"*10
print node.tagName
print "==="*20
impl=getDOMImplementation()
newdoc=impl.createDocument(None , "some_tag", None)
top_element=newdoc.documentElement
node1=newdoc.createTextNode("node1")
node2=newdoc.createTextNode("node2")
node3=newdoc.createTextNode("node3")
top_element.appendChild(node1)
top_element.appendChild(node2)
top_element.appendChild(node3)
top_element.removeChild(node3)
top_element.insertBefore(node3,node2)
print top_element.childNodes
  运行结果:
& link type=" text/css " rel=" stylesheet " href=" /css/common.css " /&
& link type=" text/css " rel=" stylesheet " href=" /Skins/kubrick/style.css " /&
& link type=" text/css " rel=" stylesheet " href=" /css/common2.css " /&
& link type=" text/css " rel=" stylesheet " href=" /css/shCore.css " /&
& link type=" text/css " rel=" stylesheet " href=" /css/shThemeDefault.css " /&
& link type=" application/rss+xml " rel=" alternate " href=" /rollenholt/rss " /&
& link type=" application/rsd+xml " rel=" EditURI " href=" /rollenholt/rsd.xml " /&
& link type=" application/wlwmanifest+xml " rel=" wlwmanifest " href=" /rollenholt/wlwmanifest.xml " /&
通过另外一种方式获得link标签
text/css stylesheet /css/common.css
text/css stylesheet /Skins/kubrick/style.css
text/css stylesheet /css/common2.css
text/css stylesheet /css/shCore.css
text/css stylesheet /css/shThemeDefault.css
application/rss+xml alternate /rollenholt/rss
application/rsd+xml EditURI /rollenholt/rsd.xml
application/wlwmanifest+xml wlwmanifest /rollenholt/wlwmanifest.xml
['ATTRIBUTE_NODE', 'CDATA_SECTION_NODE', 'COMMENT_NODE', 'DOCUMENT_FRAGMENT_NODE', 'DOCUMENT_NODE', 'DOCUMENT_TYPE_NODE', 'ELEMENT_NODE', 'ENTITY_NODE', 'ENTITY_REFERENCE_NODE', 'NOTATION_NODE', 'PROCESSING_INSTRUCTION_NODE', 'TEXT_NODE', '__doc__', '__init__', '__module__', '__nonzero__', '__repr__', '_attrs', '_attrsNS', '_call_user_data_handler', '_child_node_types', '_get_attributes', '_get_childNodes', '_get_firstChild', '_get_lastChild', '_get_localName', '_get_tagName', '_magic_id_nodes', 'appendChild', 'attributes', 'childNodes', 'cloneNode', 'firstChild', 'getAttribute', 'getAttributeNS', 'getAttributeNode', 'getAttributeNodeNS', 'getElementsByTagName', 'getElementsByTagNameNS', 'getInterface', 'getUserData', 'hasAttribute', 'hasAttributeNS', 'hasAttributes', 'hasChildNodes', 'insertBefore', 'isSameNode', 'isSupported', 'lastChild', 'localName', 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue', 'normalize', 'ownerDocument', 'parentNode', 'prefix', 'previousSibling', 'removeAttribute', 'removeAttributeNS', 'removeAttributeNode', 'removeAttributeNodeNS', 'removeChild', 'replaceChild', 'schemaType', 'setAttribute', 'setAttributeNS', 'setAttributeNode', 'setAttributeNodeNS', 'setIdAttribute', 'setIdAttributeNS', 'setIdAttributeNode', 'setUserData', 'tagName', 'toprettyxml', 'toxml', 'unlink', 'writexml']
&DOM Element: head at 0x1b3e968&
1 None link
&xml.dom.minidom.NamedNodeMap object at 0x01B4D648&
http://www.w3.org/1999/xhtml
&DOM Text node "u'\n'"&
--------------------
============================================================
[&DOM Text node "'node1'"&, &DOM Text node "'node3'"&, &DOM Text node "'node2'"&]利用Xerces-C++提高XML应用程序的性能
日期:作者:来源:IBM
&&&&&&&&&&&&&&&&&&
  XML已成为应用程序之间和在Web上进行数据交换的主要组成。通过本文学习如何适当地使用Xerces-C++来提高XML应用程序的性能。您将了解到有效使用解析器的最佳方法以及哪些特性和属性将影响解析器的性能。
  随着Web服务和面向服务架构(SOA)的出现,XML已变得非常流行。它对于应用程序之间和Web上的数据交换起着非常重要的作用,并且是许多性能关键型场景的基础。
  您可以通过有效地使用解析器提高XML应用程序的性能。Xerces-C++ 是可从Apache获得的开放源码XML验证解析器。本文将展示许多利用Xerces-C++解析器提高应用程序性能的技巧。
  Xerces-C++是一个作为共享库提供的XML验证解析器。这个库包含针对DOM和SAX的接口。具体地说,SAXParser是针对SAX 1.0规范的接口:SAX2XMLReader是针对SAX 2.0规范的接口;XercesDOMParser是针对DOM规范的接口;DOMBuilder是DOM Level 3.0 Abstract Schemas and Load and Save规范的Load接口的一个实现。
  属性和特性
  许多属性和特性对解析器的性能都有很大的影响。
  使用正确的扫描程序
  Xerces-C++的主要组件之一是扫描程序。它不只负责扫描XML实例,而且在评定XML文档的有效性方面起着重要作用。
  Xerces-C++有四个扫描程序:IGXMLScanner、WFXMLScanner、DGXMLScanner和SGXMLScanner。为您的场景选择合适的扫描程序对于获得更好的性能非常重要。IGXMLScanner(默认的扫描程序)是一个通用的扫描程序,它不仅处理格式是否良好,而且针对DTD和/或XML Schema验证XML文档。另一方面,WFXMLScanner只负责检查格式是否良好而不进行语法验证。如果您只关注文档的格式良好性就使用WFXMLScanner。如果只进行DTD验证就使用 DGXMLScanner,如果只进行XML Schema验证就使用SGXMLScanner。
  通过在SAX2XMLReader API或DOMBuilder API中设置扫描程序属性,可以通知解析器使用哪个扫描程序。清单1说明如何在SAX2XMLReader上设置扫描程序。
  清单 1. 在SAX2XMLReader API上设置扫描程序 &&&&&&&&&&&&&&&   #include &xercesc/internal/XMLGrammarPoolImpl.hpp&  #include &xercesc/sax2/XMLReaderFactory.hpp&  #include &xercesc/util/XMLUni.hpp&
  XMLGrammarPool *grammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);  SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& XMLPlatformUtils::fgMemoryManager, grammarPool);
  parser-&setProperty(XMLUni::fgXercesScannerName, (void *)XMLUni::fgSGXMLScanner);&  对SAXParser API或XercesDOMParser API,您可以调用useScanner方法来指定解析器应该使用哪个扫描程序,如 清单2所示。
  清单 2. 在SAXParser API上设置扫描程序&&&&&&&&&&&&&&&   #include &xercesc/parsers/SAXParser.hpp&  #include &xercesc/util/XMLUni.hpp&&&&&  SAXParser parser = new SAXParser();  parser-&useScanner(XMLUni::fgDGXMLScanner);&  要了解更多关于如何在Xerces-C++中使用特定扫描程序的信息,请参阅 参考资料。
  控制验证
  指定了使用哪种扫描程序后,您仍然可以使用一些特性来控制解析器是否执行验证。
  通过在SAX2XMLReader API或DOMBuilder API中设置验证特性,可以告诉解析器如何验证一个实例文档。清单3说明了如何实现上述功能。
  清单 3. 在DOMBuilder API中设置验证&&&&&&&&&&&&&&&   #include &xercesc/dom/DOMImplementationLS.hpp&  #include &xercesc/dom/DOMImplementationRegistry.hpp&  #include &xercesc/dom/DOMBuilder.hpp&  #include &xercesc/util/XMLUni.hpp&&&&&  static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };  DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);  DOMBuilder *parser = ((DOMImplementationLS*)impl)-&createDOMBuilder(&&&&&&&&&&&&&&&&&&&&&& DOMImplementationLS::MODE_SYNchrONOUS, 0);
  /* specify a validating parse */  parser-&setFeature(XMLUni::fgDOMValidateIfSchema, true);  parser-&setFeature(XMLUni::fgDOMValidation, true);
  /* for SAX2 use XMLUni::fgSAX2CoreValidation and   XMLUni::fgXercesDynamic */&  对SAXParser API或XercesDOMParser API,您可以调用 setValidationScheme方法来指定验证,如清单4所示。
  清单 4. 在XercesDOMParser API中设置验证&&&&&&&&&&&&&&&   #include &xercesc/parsers/XercesDOMParser.hpp&
  XercesDOMParser *parser = new XercesDOMParser();  /* specify a non-validating parse */  parser-&setValidationScheme(XercesDOMParser::Val_Never);&&&  其他特性
  表1展示了一些影响解析器性能的其他特性。
  表1. 其他Xerces-C++性能特性
  SAX2/DOM Level 3 setFeature XMLUni成员 说明   SAX1/Xerces DOM 解析器设置方法   fgXercesLoadExternalDTD& 控制是否解析外部的 DTD setLoadExternalDTD&   fgXercesCalculateSrcOfs& 控制对源代码偏移量的计算,此特性开销较大 setCalculateSrcOfs&   fgXercesIdentityConstraintChecking& 控制是否检查模式一致性约束 setIdentityConstraintChecking&   fgXercesIgnoreAnnotations& 控制在遍历模式时是否忽略注释 setIgnoreAnnotations&   fgXercesSchemaFullChecking& 控制是否全面检查模式中的额外错误(查找这些错误非常耗时或消耗内存) setValidationSchemaFullChecking&
  Xerces-C++ 编程指南(参阅 参考资料)描述了 Xerces-C++ 的特性。
  数据处理
  一些API对解析器的性能有重大影响,因为对具有单一实例的文档进行解析可能会大量调用这些函数。
  避免对XMLString::transcode()进行不必要的调用
  如果您提前知道要进行编码转换的字符串的内容,最好为该字符串创建一个XMLCh字符串常量,如清单5所示,而不是调用XMLString::transcode()。
  清单5. 定义XMLCh字符串&&&&&&&&&&&&&&&   // define a constant XMLCh string for ’Element_Name’#include &xercesc/util/XMLUniDefs.hpp&
  XMLCh Element_Name[] = {& chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, &&&&&&&&&&&&&&&&&&&&&&&&& chLatin_n, chLatin_t, chUnderscore,   chLatin_N, chLatin_a, &&&&&&&&&&&&&&&&&&&&&&&&& chLatin_m, chLatin_e, chNull }; &  通过使用常量字符串,可以避免分配内存、复制字符串和编码转换过程。您也不必释放由transcode函数返回的内存,因为此时这是调用者的责任。频繁地在XMLCh和char之间进行编码转换会严重影响性能,因此在可能的情况下尽量使用一种格式处理数据。
  获得XMLCh字符串常量的一个简单方法是使用脚本目录中的 makeStringDefinition.pl。Xerces-C++ 使用许多在头文件 xercesc/util/XMLUni.hpp 中定义的预定义符号。
  避免调用XMLString::stringLen()来检查零长度的字符串
  如果您只是想要检查一个零长度字符串,而不是调用 XMLString::stringLen(string),只需要检查该字符串是不是NULL或者它的第一个字符是不是空字符。清单6说明如何避免使用 XMLString::stringLen()来检查一个零长度的字符串。
  清单6. 检查零长度字符串&&&&&&&&&&&&&&&   if (xmlStr == 0 || *xmlStr == 0) {// string is zero length}&  这段代码帮助您避免额外地传递字符串。
  避免调用XMLString::compareIString()
  XMLString::compareIString()方法使用编码转换程序来进行不区分大小写的字符串比较。如果已知所要比较的数据只有字母字符(A到Z),您应该使用 XMLString::compareIStringASCII()例程。这个例程检查字符是否在A到Z之间,然后将其转换为小写字母并将它直接和其他字符比较。
  使用XMLString::compareIStringASCII()避免了调用编码转换服务执行比较。作为一种替代方法,您可以调用 XMLString::equals()方法。清单7展示了三种方法。
  清单7. 字符串比较&&&&&&&&&&&&&&&   #include &xercesc/util/XMLString.hpp&
  XMLCh*&  XMLCh Element[] = {& chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, &&&&&&&&&&&&&&&&&&&& chLatin_n, chLatin_t, chNull };
  if (XMLString::compareIString(data, Element) == 0) { ... }/* Since Element only has the characters A to Z, this could be done more && efficiently using: */  if (XMLString::compareIStringASCII(data, Element) == 0) { ... }
  /* Even better is when you don’t require a case-sensitive comparison */
  if (XMLString::equals(data, Element)) { ... }&  最小化处理程序
  如果您只想测试一个文档是否格式良好和(或)是否是有效的,只要注册一个ErrorHandler。当注册一个 DocumentHandler 和/或AdvDocHandler 时,将执行从Xerces-C++ 库到应用程序的额外的不必要的调用,如果使用 AdvDocHandler 只为了得到XMLDecl回调信息,您就可以在获得XMLDecl信息后调用removeAdvDocHandler。
  在序列化过程中避免使用XMLFormatter::UnRep_Fail
  如果您试图格式化XML,请谨慎地使用XMLFormatter::UnRep_Fail。这个选项将检查每个字符,查看它是否可以被转换成目标编码。如果原始文档的编码和目标编码相同,并且目标编码中的修改仍然有效,您应该使用 XMLFormatter::UnRep_charRef。
  模式语法缓存
  如果进行模式验证和重用同一模式,需要使用Xerces-C++的语法缓存特性。更多信息请查看developerWorks文章“使用 Xerces-C++缓存和序列化 XML模式”(请参阅 参考资料)。
  Xerces-C++初始化
  根据Xerces-C++线程模型,主线程调用 XMLPlatformUtils::Initialize()。然后您可以创建其他用于解析的线程(每个线程创建一个解析器)。最后主线程调用 XMLPlatformUtils::Terminate()。
  XMLPlatformUtils::Initialize()是一个开销较大的操作。即使不使用多线程处理,也要预先初始化Xerces-C++以避免多次调用这个函数,然后在应用程序结束时将其终止。如清单 8 所示,将 XMLPlatformUtils::Initialize的最后一个参数toInitStatics指定为true,将使初始化过程变得更长,但它能产生更好的解析性能,因为它预先初始化了所有静态变量。
  清单8. 通过初始化调用实现所有静态变量的初始化&&&&&&&&&&&&&&&   #include &xercesc/util/PlatformUtils.hpp&&&&&  XMLPlatformUtils::Initalize(XMLUni::fgXercescDefaultLocale, 0, 0, 0, true);&& &  类似地,在初始化期间可以创建一个解析器池(每个线程创建一个)。当需要解析文档时,可以在运行时使用这些解析器,从而避免构造和分解解析器的开销。
  结束语
  在本文中,我们展示了许多关于如何使用Xerces-C++ XML解析器提高应用程序性能的技巧和建议。采用这些建议能够降低解析XML文档时Xerces-C++的CPU消耗。
  关于作者    David Cargill是加拿大IBM XML Parser Development团队的成员之一。过去五年中他参与了Xerces-C++解析器的开发工作。
微信公众号
TechTarget
TechTarget中国
Gartner认为iBPM要比运营型智能平台更优秀,表现在以下几个方面:iBPM套件提供更好的工作流,适配性案例管理以及结构化流程协调能力。
云端业务流程管理已经不再是什么新鲜事,更不再是什么可怕的方法来管理重要的业务流程。现在,它已经普遍被认为是一种新常态。组织已经从这一技术中获益,使它来更有效地访问和管理企业信息。
随着云技术的不断采用,现代企业都面临着重大的集成问题。现在已经不再是把企业内部的数据和应用简单地缝合在一起,企业IT现在面临着整合着外部与内部信息的难题。
2014将会是API管理方法新旧PK的一年,据Delyn Simons说,她领导了Mashery开发者的外展团队。应用编程接口(API)的主流化和私有化在新的一年也将掀起波澜,她在波士顿“Future Insights Ultimate Developer Event 2013”大会上预测说。
企业级IT网站群
TechTarget中国 版权所有
All Rights Reserved, Copyright
TechTarget中国 版权所有
All Rights Reserved, CopyrightProgramming with DOM
Questions&Answers&Is Xerces DOM implementation thread-safe?& No. DOM does not require implementations to be thread safe.
If you need to access the DOM from multiple threads,
you are required to add the appropriate locks
to your application code.
How do I create a DOM parser?&
You can create a DOM parser by using
the Java APIs for
XML Processing (JAXP) or using the DOM Level 3 Load and Save.
The following source code shows how to create the parser with JAXP:
import java.io.IOE
import javax.xml.parsers.DocumentB
import javax.xml.parsers.DocumentBuilderF
import javax.xml.parsers.FactoryConfigurationE
import javax.xml.parsers.ParserConfigurationE
import org.w3c.dom.D
import org.xml.sax.SAXE
String xmlFile = &file:///xerces-2_11_0/data/personal.xml&;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlFile);
catch (FactoryConfigurationError e) {
// unable to get a document builder factory
catch (ParserConfigurationException e) {
// parser was unable to be configured
catch (SAXException e) {
// parsing error
catch (IOException e) {
// i/o error
The following source code shows how to create the parser using :
org.w3c.dom.bootstrap.DOMImplementationR
org.w3c.dom.D
org.w3c.dom.ls.DOMImplementationLS;
org.w3c.dom.ls.LSP
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS)registry.getDOMImplementation(&LS&);
LSParser builder = impl.createLSParser(
DOMImplementationLS.MODE_SYNCHRONOUS, null);
Document document = builder.parseURI(&data/personal.xml&);
You can now use DOM Level 3 Load/Save and Core interfaces with the regular Xerces distribution.
How do I serialize DOM to an output stream?&
You can serialize a DOM tree by using the DOM Level 3 Load and Save.
LSSerializer performs automatic namespace fixup to make your document namespace
well-formed.
org.w3c.dom.bootstrap.DOMImplementationR
org.w3c.dom.D
org.w3c.dom.ls.DOMImplementationLS;
org.w3c.dom.ls.LSS
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS)registry.getDOMImplementation(&LS&);
LSSerializer writer = impl.createLSSerializer();
String str = writer.writeToString(document);
You can also serialize a DOM tree by using the JAXP Transformer API.
It is also possible to serialize a DOM tree by using the Xerces org.apache.xml.XMLSerializer serialization code directly.
This non-standard way of serializing a DOM has been deprecated since Xerces-J 2.9.0 and should be avoided if possible.
import org.apache.xml.serialize.OutputF
import org.apache.xml.serialize.XMLS
import org.apache.xml.serialize.LineS
OutputFormat format = new OutputFormat((Document)core);
format.setLineSeparator(LineSeparator.Windows);
format.setIndenting(true);
format.setLineWidth(0);
format.setPreserveSpace(true);
XMLSerializer serializer = new XMLSerializer (
new FileOutputStream(&output.xml&), format);
serializer.asDOMSerializer();
serializer.serialize(document);
Does Xerces DOM implement java.io.Serializable?&
Yes. Xerces DOM can be serialized using Java object serialization.
It is recommended that a DOM be serialized as
where possible
instead of using object serialization.
By choosing object serialization you sacrifice interoperability
between parsers and we do not guarantee interoperability
between versions of Xerces. It should be used with caution.
Some rough measurements have shown that XML serialization performs
better than Java object serialization and that XML instance documents
require less storage space than object serialized DOMs.
How do I supply my own implementation of the DOM?&
to register your own implementation of the
org.w3c.dom.Document interface.
Xerces provides the following implementations of the
org.w3c.dom.Document interface:
org.apache.xerces.dom.CoreDocumentImpl --
supports DOM Level 3 Core Recommendation.
org.apache.xerces.dom.DocumentImpl --
supports DOM Level 3 Core, Mutation Events, Traversal and Ranges.
org.apache.xerces.dom.PSVIDocumentImpl --
provides access to the post schema validation infoset via DOM.
How do I access the DOM Level 3 functionality?&
The DOM Level 3 functionality is now exposed by default since Xerces-J 2.7.0.
The experimental interfaces which were once present in the org.apache.xerces.dom3
package no longer exist. This package existed primarily so that the DOM Level 2
and DOM Level 3 implementations in Xerces-J 2.6.2 and prior could co-exist. Code which
depended on the org.apache.xerces.dom3 package must be modified to use the
official DOM Level 3 API located in the org.w3c.dom.* packages.
For more information, refer to the
How do I run DOM Level 3 applications under JDK 1.4 and higher?&
to specify xercesImpl.jar and xml-apis.jar.
A more complete description is available .
How do I retrieve PSVI from the DOM?&
By default Xerces does not store the PSVI information in the DOM tree.
The following source shows you how to parse an XML document (using JAXP) and how to retrieve PSVI (using the ):
//dbf is JAXP DocumentBuilderFactory
// all of the following features must be set:
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setAttribute(&http://apache.org/xml/features/validation/schema&,
Boolean.TRUE);
// you also must specify Xerces PSVI DOM implementation
// &org.apache.xerces.dom.PSVIDocumentImpl&
dbf.setAttribute(&http://apache.org/xml/properties/dom/document-class-name&,
&org.apache.xerces.dom.PSVIDocumentImpl&);
Document doc = db.parse(args[0]);
if (doc.getDocumentElement().isSupported(&psvi&, &1.0&)){
ElementPSVI psviElem = (ElementPSVI)doc.getDocumentElement();
XSElementDeclaration decl = psviElem.getElementDeclaration();
If you want to build the DOM tree in memory and be able to access the PSVI information you need to start by instantiating org.apache.xerces.dom.PSVIDocumentImpl or you need to use the DOM Level 3 API as shown in the following example:
System.setProperty(DOMImplementationRegistry.PROPERTY,
&org.apache.xerces.dom.DOMXSImplementationSourceImpl&);
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementation impl =
(DOMImplementation) registry.getDOMImplementation(&psvi&);
The PSVI information will not be added or modified as you modify the tree in memory. Instead, if you want to get updated PSVI information, you need to validate your DOM in memory using the
method as described in the .
You can find more information about how to use the XML Schema API .
How can I make sure that my DOM document in memory conforms to a schema?&
DOM revalidation is supported via W3C DOM Level 3 Core
Document.normalizeDocument().
This release only supports revalidation against XML Schemas and DTDs. Revalidation against other schema types is not implemented.
To revalidate the document you need:
the DOMParser.
Retrieve DOMConfiguration from the Document,
and set validate feature to true.
Provide XML Schemas (agains which validation should occur)
by either setting xsi:schemaLocation /
xsi:noSchemaLocation attributes on the documentElement, or
by setting schema-location parameter on the
DOMConfiguration.
Relative URIs for the schema documents will be resolved relative to the
(which should be set).
Otherwise, you can implement your own LSResourceResolver and set it
via resource-resolver on the DOMConfiguration.
Note: if a document contains any DOM Level 1 nodes (the nodes created using createElement,
createAttribute, etc.) a fatal error will occur as described in the
algorithm.
In general, the
discourages using DOM Level 1 nodes in the namespace aware application:
DOM Level 1 methods are namespace ignorant. Therefore, while it is safe to use these methods when not
dealing with namespaces, using them and the new ones at the same time should be avoided. DOM Level 1 methods
solely identify attribute nodes by their nodeName. On the contrary, the DOM Level 2 methods related to namespaces,
identify attribute nodes by their namespaceURI and localName. Because of this fundamental difference, mixing both
sets of methods can lead to unpredictable results.
import org.w3c.dom.D
import org.w3c.dom.DOMC
import org.w3c.dom.ls.LSP
Document document = builder.parseURI(&data/personal-schema.xml&);
DOMConfiguration config = document.getDomConfig();
config.setParameter(&error-handler&,new MyErrorHandler());
config.setParameter(&schema-type&, &http://www.w3.org/2001/XMLSchema&);
config.setParameter(&validate&, Boolean.TRUE);
document.normalizeDocument();
For more information, please refer to the
How do I handle errors?&
You should register an error handler with the parser by supplying
a class which implements the org.xml.sax.ErrorHandler
interface. This is true regardless of whether your parser is a
DOM based or SAX based parser.
You can register an error handler on a DocumentBuilder
created using JAXP like this:
import javax.xml.parsers.DocumentB
import org.xml.sax.ErrorH
import org.xml.sax.SAXE
import org.xml.sax.SAXParseE
ErrorHandler handler = new ErrorHandler() {
public void warning(SAXParseException e) throws SAXException {
System.err.println(&[warning] &+e.getMessage());
public void error(SAXParseException e) throws SAXException {
System.err.println(&[error] &+e.getMessage());
public void fatalError(SAXParseException e) throws SAXException {
System.err.println(&[fatal error] &+e.getMessage());
DocumentBuilder builder = /* builder instance */;
builder.setErrorHandler(handler);
If you are using
you can register an error handler with the LSParser by supplying
a class which implements the org.w3c.dom.DOMErrorHandler
interface. Note: all exceptions during parsing or saving XML data
are reported via DOMErrorHandler.
How can I control the way that entities are represented in the DOM?&
The Xerces
http://apache.org/xml/features/dom/create-entity-ref-nodes
(or corresponding DOM Level 3 LSParser entities feature)
controls how entities appear in the DOM tree. When one of those features
is set to true (the default), an occurrence of an entity reference
in the XML document will be represented by a subtree with an
EntityReference node at the root whose children represent the
entity expansion.
If the feature is false, an entity reference in the XML document
is represented by only the nodes that represent the entity
expansion.
In either case, the entity expansion will be a DOM tree
representing the structure of the entity expansion, not a text
node containing the entity expansion as text.
How do I associate my own data with a node in the DOM tree?&
The class org.apache.xerces.dom.NodeImpl provides the
setUserData(Object o) and the Object
getUserData() methods that you can use to attach any object
to a node in the DOM tree.
Beware that you should try and remove references to your data on
nodes you no longer use (by calling setUserData(null),
or these nodes will not be garbage collected until the entire
document is garbage collected.
If you are using Xerces with the DOM Level 3 support
you can use org.w3c.dom.Node.setUserData() and register your own
UserDataHandler.
Why does getElementById not work for documents validated against XML Schemas?&
Make sure the
are turned on before you parse a document.
How do I specify an ID attribute in the DOM?& You can use the DOM level 3 setIdAttribute, setIdAttributeNS, and setIdAttributeNode methods
to specify ID attribute in the DOM. See .
How do I access type information in the DOM?&
interface that exposes type information for
element and attribute nodes. The type information depends on the document schema and is only available
if Xerces was able to find the corresponding grammar (DOM Level 3 validate or
validate-if-schema feature must be turned on).
If you need to access the full PSVI in the DOM please refer to .
Copyright &
The Apache Software Foundation.
All Rights Reserved.}

我要回帖

更多关于 pb registryget 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信