本文整理匯總了Java中org.w3c.dom.Node.CDATA_SECTION_NODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Node.CDATA_SECTION_NODE屬性的具體用法?Java Node.CDATA_SECTION_NODE怎麽用?Java Node.CDATA_SECTION_NODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.CDATA_SECTION_NODE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNodeKind
public int getNodeKind()
{
switch (node.getNodeType())
{
case Node.ATTRIBUTE_NODE:
return MFNodeKind_Attribute; // also field?
case Node.CDATA_SECTION_NODE:
return MFNodeKind_Text | MFNodeKind_CData;
case Node.COMMENT_NODE:
return MFNodeKind_Comment;
case Node.DOCUMENT_NODE:
return MFNodeKind_Document;
case Node.ELEMENT_NODE:
return MFNodeKind_Element;
case Node.TEXT_NODE:
return MFNodeKind_Text;
case Node.PROCESSING_INSTRUCTION_NODE:
return MFNodeKind_ProcessingInstruction;
default:
return 0;
}
}
示例2: getText
public static String getText(Element node) {
StringBuffer sb = new StringBuffer();
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node child = list.item(i);
switch (child.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
sb.append(child.getNodeValue());
}
}
return sb.toString();
}
示例3: endNode
/**
* End processing of given node
*
*
* @param node Node we just finished processing
*
* @throws org.xml.sax.SAXException
*/
protected void endNode(Node node) throws org.xml.sax.SAXException {
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE :
break;
case Node.DOCUMENT_TYPE_NODE :
serializeDocType((DocumentType) node, false);
break;
case Node.ELEMENT_NODE :
serializeElement((Element) node, false);
break;
case Node.CDATA_SECTION_NODE :
break;
case Node.ENTITY_REFERENCE_NODE :
serializeEntityReference((EntityReference) node, false);
break;
default :
}
}
示例4: serializeBody
public void serializeBody(Object element, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
NodeList childNodes = ((Element)element).getChildNodes();
int len = childNodes.getLength();
for( int i=0; i<len; i++ ) {
Node child = childNodes.item(i);
switch(child.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
target.text(child.getNodeValue(),null);
break;
case Node.ELEMENT_NODE:
target.writeDom((Element)child,domHandler,null,null);
break;
}
}
}
示例5: getWholeTextForward
/**
* Concatenates the text of all logically-adjacent text nodes to the
* right of this node
* @param node
* @param buffer
* @param parent
* @return true - if execution was stopped because the type of node
* other than EntityRef, Text, CDATA is encountered, otherwise
* return false
*/
private boolean getWholeTextForward(Node node, StringBuffer buffer, Node parent){
// boolean to indicate whether node is a child of an entity reference
boolean inEntRef = false;
if (parent!=null) {
inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
}
while (node != null) {
short type = node.getNodeType();
if (type == Node.ENTITY_REFERENCE_NODE) {
if (getWholeTextForward(node.getFirstChild(), buffer, node)){
return true;
}
}
else if (type == Node.TEXT_NODE ||
type == Node.CDATA_SECTION_NODE) {
((NodeImpl)node).getTextContent(buffer);
}
else {
return true;
}
node = node.getNextSibling();
}
// if the parent node is an entity reference node, must
// check nodes to the right of the parent entity reference node for logically adjacent
// text nodes
if (inEntRef) {
getWholeTextForward(parent.getNextSibling(), buffer, parent.getParentNode());
return true;
}
return false;
}
示例6: getNodeData
/**
* Retrieve the text content of a DOM subtree, appending it into a
* user-supplied FastStringBuffer object. Note that attributes are
* not considered part of the content of an element.
* <p>
* There are open questions regarding whitespace stripping.
* Currently we make no special effort in that regard, since the standard
* DOM doesn't yet provide DTD-based information to distinguish
* whitespace-in-element-context from genuine #PCDATA. Note that we
* should probably also consider xml:space if/when we address this.
* DOM Level 3 may solve the problem for us.
* <p>
* %REVIEW% Actually, since this method operates on the DOM side of the
* fence rather than the DTM side, it SHOULDN'T do
* any special handling. The DOM does what the DOM does; if you want
* DTM-level abstractions, use DTM-level methods.
*
* @param node Node whose subtree is to be walked, gathering the
* contents of all Text or CDATASection nodes.
* @param buf FastStringBuffer into which the contents of the text
* nodes are to be concatenated.
*/
protected static void getNodeData(Node node, FastStringBuffer buf)
{
switch (node.getNodeType())
{
case Node.DOCUMENT_FRAGMENT_NODE :
case Node.DOCUMENT_NODE :
case Node.ELEMENT_NODE :
{
for (Node child = node.getFirstChild(); null != child;
child = child.getNextSibling())
{
getNodeData(child, buf);
}
}
break;
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE :
case Node.ATTRIBUTE_NODE : // Never a child but might be our starting node
buf.append(node.getNodeValue());
break;
case Node.PROCESSING_INSTRUCTION_NODE :
// warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
break;
default :
// ignore
break;
}
}
示例7: setSource
public static void setSource(@NonNull Node node, @NonNull File source) {
//noinspection ConstantConditions
for (; node != null; node = node.getNextSibling()) {
short nodeType = node.getNodeType();
if (nodeType == Node.ELEMENT_NODE
|| nodeType == Node.COMMENT_NODE
|| nodeType == Node.DOCUMENT_NODE
|| nodeType == Node.CDATA_SECTION_NODE) {
node.setUserData(DATA_ORIGIN_FILE, source, null);
}
Node child = node.getFirstChild();
setSource(child, source);
}
}
示例8: getNodeTypeFromCode
private String getNodeTypeFromCode(short code) {
String retval = null;
switch (code) {
case Node.ATTRIBUTE_NODE :
retval = "ATTRIBUTE_NODE"; break;
case Node.CDATA_SECTION_NODE :
retval = "CDATA_SECTION_NODE"; break;
case Node.COMMENT_NODE :
retval = "COMMENT_NODE"; break;
case Node.DOCUMENT_FRAGMENT_NODE :
retval = "DOCUMENT_FRAGMENT_NODE"; break;
case Node.DOCUMENT_NODE :
retval = "DOCUMENT_NODE"; break;
case Node.DOCUMENT_TYPE_NODE :
retval = "DOCUMENT_TYPE_NODE"; break;
case Node.ELEMENT_NODE :
retval = "ELEMENT_NODE"; break;
case Node.ENTITY_NODE :
retval = "ENTITY_NODE"; break;
case Node.ENTITY_REFERENCE_NODE :
retval = "ENTITY_REFERENCE_NODE"; break;
case Node.NOTATION_NODE :
retval = "NOTATION_NODE"; break;
case Node.PROCESSING_INSTRUCTION_NODE :
retval = "PROCESSING_INSTRUCTION_NODE"; break;
case Node.TEXT_NODE:
retval = "TEXT_NODE"; break;
}
return retval;
}
示例9: elementToString
public static String elementToString(Node n) {
String name = n.getNodeName();
short type = n.getNodeType();
if (Node.CDATA_SECTION_NODE == type) {
return "<![CDATA[" + n.getNodeValue() + "]]>";
}
if (name.startsWith("#")) {
return "";
}
StringBuffer sb = new StringBuffer();
sb.append('<').append(name);
NamedNodeMap attrs = n.getAttributes();
if (attrs != null) {
for (int i = 0; i < attrs.getLength(); i++) {
Node attr = attrs.item(i);
sb.append(' ').append(attr.getNodeName()).append("=\"")
.append(attr.getNodeValue()).append("\"");
}
}
String textContent = null;
NodeList children = n.getChildNodes();
if (children.getLength() == 0) {
if ((textContent = n.getTextContent()) != null
&& !"".equals(textContent)) {
sb.append(textContent).append("</").append(name).append('>');
} else {
sb.append("/>").append('\n');
}
} else {
sb.append('>').append('\n');
boolean hasValidChildren = false;
for (int i = 0; i < children.getLength(); i++) {
String childToString = elementToString(children.item(i));
if (!"".equals(childToString)) {
sb.append(childToString);
hasValidChildren = true;
}
}
if (!hasValidChildren
&& ((textContent = n.getTextContent()) != null)) {
sb.append(textContent);
}
sb.append("</").append(name).append('>');
}
return sb.toString();
}
示例10: dispatchNodeData
/**
* Retrieve the text content of a DOM subtree, appending it into a
* user-supplied FastStringBuffer object. Note that attributes are
* not considered part of the content of an element.
* <p>
* There are open questions regarding whitespace stripping.
* Currently we make no special effort in that regard, since the standard
* DOM doesn't yet provide DTD-based information to distinguish
* whitespace-in-element-context from genuine #PCDATA. Note that we
* should probably also consider xml:space if/when we address this.
* DOM Level 3 may solve the problem for us.
* <p>
* %REVIEW% Note that as a DOM-level operation, it can be argued that this
* routine _shouldn't_ perform any processing beyond what the DOM already
* does, and that whitespace stripping and so on belong at the DTM level.
* If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM.
*
* @param node Node whose subtree is to be walked, gathering the
* contents of all Text or CDATASection nodes.
*/
protected static void dispatchNodeData(Node node,
org.xml.sax.ContentHandler ch,
int depth)
throws org.xml.sax.SAXException
{
switch (node.getNodeType())
{
case Node.DOCUMENT_FRAGMENT_NODE :
case Node.DOCUMENT_NODE :
case Node.ELEMENT_NODE :
{
for (Node child = node.getFirstChild(); null != child;
child = child.getNextSibling())
{
dispatchNodeData(child, ch, depth+1);
}
}
break;
case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW%
case Node.COMMENT_NODE :
if(0 != depth)
break;
// NOTE: Because this operation works in the DOM space, it does _not_ attempt
// to perform Text Coalition. That should only be done in DTM space.
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE :
case Node.ATTRIBUTE_NODE :
String str = node.getNodeValue();
if(ch instanceof CharacterNodeHandler)
{
((CharacterNodeHandler)ch).characters(node);
}
else
{
ch.characters(str.toCharArray(), 0, str.length());
}
break;
// /* case Node.PROCESSING_INSTRUCTION_NODE :
// // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
// break; */
default :
// ignore
break;
}
}
示例11: elementToString
public static String elementToString(Node n) throws Exception {
try {
String name = n.getNodeName();
short type = n.getNodeType();
if (Node.CDATA_SECTION_NODE == type) {
return "<![CDATA[" + n.getNodeValue() + "]]>";
}
if (name.startsWith("#")) {
return "";
}
StringBuffer sb = new StringBuffer();
sb.append('<').append(name);
NamedNodeMap attrs = n.getAttributes();
if (attrs != null) {
for (int i = 0; i < attrs.getLength(); i++) {
Node attr = attrs.item(i);
sb.append(' ').append(attr.getNodeName()).append("=\"")
.append(attr.getNodeValue()).append("\"");
}
}
String textContent = null;
NodeList children = n.getChildNodes();
if (children.getLength() == 0) {
if ((textContent = n.getTextContent()) != null
&& !"".equals(textContent)) {
sb.append(textContent).append("</").append(name)
.append('>');
} else {
sb.append("/>").append('\n');
}
} else {
sb.append('>').append('\n');
boolean hasValidChildren = false;
for (int i = 0; i < children.getLength(); i++) {
String childToString = elementToString(children.item(i));
if (!"".equals(childToString)) {
sb.append(childToString);
hasValidChildren = true;
}
}
if (!hasValidChildren
&& ((textContent = n.getTextContent()) != null)) {
sb.append(textContent);
}
sb.append("</").append(name).append('>');
}
return sb.toString();
} catch (Exception e) {
log.error(e);
log.error(e.getStackTrace());
throw (e);
}
}
示例12: writeAnyNode
/**
* Write any node.
*
* @param node
* the node
* @throws ShellException
* the shell exception
*/
protected void writeAnyNode(Node node) throws ShellException {
// is there anything to do?
if (node == null) {
return;
}
short type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE:
write((Document) node);
break;
case Node.DOCUMENT_TYPE_NODE:
write((DocumentType) node);
break;
case Node.ELEMENT_NODE:
write((Element) node);
break;
case Node.ENTITY_REFERENCE_NODE:
write((EntityReference) node);
break;
case Node.CDATA_SECTION_NODE:
write((CDATASection) node);
break;
case Node.TEXT_NODE:
write((Text) node);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
write((ProcessingInstruction) node);
break;
case Node.COMMENT_NODE:
write((Comment) node);
break;
default:
throw new ShellException(getString(
"RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
}
}
示例13: nodeSetMinusCommentNodes
/**
* Recursively traverses the subtree, and returns an XPath-equivalent
* node-set of all nodes traversed, excluding any comment nodes,
* if specified.
*
* @param node the node to traverse
* @param nodeSet the set of nodes traversed so far
* @param the previous sibling node
*/
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
Node prevSibling)
{
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
nodeSet.add(node);
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
for (int i = 0, len = attrs.getLength(); i < len; i++) {
nodeSet.add(attrs.item(i));
}
}
Node pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.DOCUMENT_NODE :
pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE:
// emulate XPath which only returns the first node in
// contiguous text/cdata nodes
if (prevSibling != null &&
(prevSibling.getNodeType() == Node.TEXT_NODE ||
prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
return;
}
nodeSet.add(node);
break;
case Node.PROCESSING_INSTRUCTION_NODE :
nodeSet.add(node);
break;
case Node.COMMENT_NODE:
if (withComments) {
nodeSet.add(node);
}
}
}
示例14: nodeSetMinusCommentNodes
/**
* Recursively traverses the subtree, and returns an XPath-equivalent
* node-set of all nodes traversed, excluding any comment nodes,
* if specified.
*
* @param node the node to traverse
* @param nodeSet the set of nodes traversed so far
* @param the previous sibling node
*/
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
Node prevSibling)
{
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
for (int i = 0, len = attrs.getLength(); i < len; i++) {
nodeSet.add(attrs.item(i));
}
}
nodeSet.add(node);
Node pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.DOCUMENT_NODE :
pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE:
// emulate XPath which only returns the first node in
// contiguous text/cdata nodes
if (prevSibling != null &&
(prevSibling.getNodeType() == Node.TEXT_NODE ||
prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
return;
}
nodeSet.add(node);
break;
case Node.PROCESSING_INSTRUCTION_NODE :
nodeSet.add(node);
break;
case Node.COMMENT_NODE:
if (withComments) {
nodeSet.add(node);
}
}
}
示例15: testNode
/**
* Test a Node.
* @param node to test
* @param test to execute
* @return true if node passes test
*/
public static boolean testNode(Node node, NodeTest test) {
if (test == null) {
return true;
}
if (test instanceof NodeNameTest) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
return false;
}
NodeNameTest nodeNameTest = (NodeNameTest) test;
QName testName = nodeNameTest.getNodeName();
String namespaceURI = nodeNameTest.getNamespaceURI();
boolean wildcard = nodeNameTest.isWildcard();
String testPrefix = testName.getPrefix();
if (wildcard && testPrefix == null) {
return true;
}
if (wildcard
|| testName.getName()
.equals(DOMNodePointer.getLocalName(node))) {
String nodeNS = DOMNodePointer.getNamespaceURI(node);
return equalStrings(namespaceURI, nodeNS) || nodeNS == null
&& equalStrings(testPrefix, getPrefix(node));
}
return false;
}
if (test instanceof NodeTypeTest) {
int nodeType = node.getNodeType();
switch (((NodeTypeTest) test).getNodeType()) {
case Compiler.NODE_TYPE_NODE :
return true;
case Compiler.NODE_TYPE_TEXT :
return nodeType == Node.CDATA_SECTION_NODE
|| nodeType == Node.TEXT_NODE;
case Compiler.NODE_TYPE_COMMENT :
return nodeType == Node.COMMENT_NODE;
case Compiler.NODE_TYPE_PI :
return nodeType == Node.PROCESSING_INSTRUCTION_NODE;
default:
return false;
}
}
if (test instanceof ProcessingInstructionTest
&& node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
String testPI = ((ProcessingInstructionTest) test).getTarget();
String nodePI = ((ProcessingInstruction) node).getTarget();
return testPI.equals(nodePI);
}
return false;
}