本文整理匯總了Java中org.w3c.dom.Node.ATTRIBUTE_NODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Node.ATTRIBUTE_NODE屬性的具體用法?Java Node.ATTRIBUTE_NODE怎麽用?Java Node.ATTRIBUTE_NODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.ATTRIBUTE_NODE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hasLegalRootContainer
/**
* Finds the root container for the given node and determines
* if that root container is legal with respect to the
* DOM 2 specification. At present, that means the root
* container must be either an attribute, a document,
* or a document fragment.
*/
private boolean hasLegalRootContainer( Node node )
{
if ( node==null )
return false;
Node rootContainer = getRootContainer( node );
switch( rootContainer.getNodeType() )
{
case Node.ATTRIBUTE_NODE:
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
return true;
}
return false;
}
示例2: getStrFromNode
/**
* Method getStrFromNode
*
* @param xpathnode
* @return the string for the node.
*/
public static String getStrFromNode(Node xpathnode) {
if (xpathnode.getNodeType() == Node.TEXT_NODE) {
// we iterate over all siblings of the context node because eventually,
// the text is "polluted" with pi's or comments
StringBuilder sb = new StringBuilder();
for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
currentSibling != null;
currentSibling = currentSibling.getNextSibling()) {
if (currentSibling.getNodeType() == Node.TEXT_NODE) {
sb.append(((Text) currentSibling).getData());
}
}
return sb.toString();
} else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
return ((Attr) xpathnode).getNodeValue();
} else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
return ((ProcessingInstruction) xpathnode).getNodeValue();
}
return null;
}
示例3: nodeToString
private static String nodeToString(Node node) {
int nodeType = node.getNodeType();
switch (nodeType) {
case Node.DOCUMENT_NODE:
return XMLUtils.prettyPrintElement(((Document) node).getDocumentElement(), true, false);
case Node.ELEMENT_NODE:
return XMLUtils.prettyPrintElement((Element) node, true, false);
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
int len = node.getChildNodes().getLength();
return ((len<2) ? node.getNodeValue():XMLUtils.getNormalizedText(node));
case Node.ATTRIBUTE_NODE:
return node.getNodeValue();
default:
return null;
}
}
示例4: nodeCount
/**
* Counts the number of matching nodes.
*/
public int nodeCount(final String path)
{
ensureRoot();
int count = 0;
final Node node = getNodeHelper(path, false, false);
if( node != null )
{
if( node.getNodeType() == Node.ATTRIBUTE_NODE )
{
count = 1;
}
else
{
for( final Iterator<String> iter = iterateValues(path); iter.hasNext(); count++ )
{
iter.next();
}
}
}
return count;
}
示例5: toMap
public Map<String, Object> toMap(Node node) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
if (child.getNodeType() == Node.ATTRIBUTE_NODE || child.getNodeType() == Node.ELEMENT_NODE)
toMap(map, child);
return map;
}
示例6: addNamespacesFrom
/**
* Adds namespaces from the tag to this context, possibly overriding namespaces
* from previously added tags. Tags should be added starting from the root down
* to the context position.
*/
private void addNamespacesFrom(SyntaxElement s) {
Node e = s.getNode();
NamedNodeMap attrs = e.getAttributes();
String nodePrefix = getPrefix(e.getNodeName(), false);
String version = null;
String xsltAttrName = null;
for (int i = attrs.getLength() - 1; i >= 0; i--) {
Node n = attrs.item(i);
if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
Attr a = (Attr)n;
String attrName = a.getName();
String value = a.getValue();
addNamespace(attrName, value, nodePrefix);
if(value.trim().equals("http://www.w3.org/1999/XSL/Transform")) { //NOI18N
xsltAttrName = attrName;
}
if(CompletionUtil.getLocalNameFromTag(attrName).
equals("version")) { //NOI18N
version = value.trim();
}
}
}
if (xsltAttrName != null && "2.0".equals(version)) {
String prefix = getPrefix(xsltAttrName, false);
if (prefix == null) {
// override nonNS location because nonNS schema is XSLT 2.0
noNamespaceSchemaLocation = "http://www.w3.org/2007/schema-for-xslt20.xsd";
} else {
addSchemaLocation(prefix + " http://www.w3.org/2007/schema-for-xslt20.xsd"); //NOI18N
}
}
}
示例7: hasWhitespaceChangeOnly
public boolean hasWhitespaceChangeOnly() {
for (ChangeInfo ci : getChanges()) {
if (ci.isDomainElement()) {
continue;
}
Node n = ci.getActualChangedNode();
if (n.getNodeType() == Node.TEXT_NODE) {
String text = ((Text)n).getNodeValue();
if (text != null && text.trim().length() > 0) {
return false;
}
} else if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
String name = ((Attr) n).getName();
Attr removed = getRemovedAttributes().get(name);
if (removed == null) {
return false;
}
Attr added = getAddedAttributes().get(name);
if (added == null) {
return false;
}
if (removed.getValue() == null ||
! removed.getValue().equals(added.getValue())) {
return false;
}
} else {
// node type must be either element or comment or cdata...
return false;
}
}
return true;
}
示例8: getParentNode
/**
*
*
* @see org.w3c.dom.Node
*/
@Override
public final Node getParentNode()
{
if (getNodeType() == Node.ATTRIBUTE_NODE)
return null;
int newnode = dtm.getParent(node);
return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
}
示例9: getTextContent
private static String getTextContent(Node node)
{
short nodeType = node.getNodeType();
if( nodeType == Node.ATTRIBUTE_NODE ||
nodeType == Node.PROCESSING_INSTRUCTION_NODE ||
nodeType == Node.COMMENT_NODE ||
nodeType == Node.TEXT_NODE ||
nodeType == Node.CDATA_SECTION_NODE )
{
return com.altova.CoreTypes.castToString(node.getNodeValue());
}
else
if( nodeType == Node.DOCUMENT_NODE ||
nodeType == Node.DOCUMENT_FRAGMENT_NODE ||
nodeType == Node.ELEMENT_NODE ||
nodeType == Node.ENTITY_REFERENCE_NODE )
{
String result = "";
Node child = node.getFirstChild();
for( ; child != null ; child = child.getNextSibling() )
{
short childNodeType = child.getNodeType();
if( childNodeType == Node.TEXT_NODE ||
childNodeType == Node.CDATA_SECTION_NODE ||
childNodeType == Node.ELEMENT_NODE ||
childNodeType == Node.ENTITY_REFERENCE_NODE )
{
result += getTextContent( child );
}
}
return result;
}
else
return "";
}
示例10: getNextSibling
/**
*
*
* @see org.w3c.dom.Node
*/
@Override
public final Node getNextSibling()
{
// Attr's Next is defined at DTM level, but not at DOM level.
if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE)
return null;
int newnode = dtm.getNextSibling(node);
return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
}
示例11: getXpathData
private Document getXpathData(Document document, String xPath) {
if (document == null) {
return null;
}
if (xPath == null) {
return null;
}
try {
Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
Element root = (Element) doc.createElement("root");
doc.appendChild(root);
NodeList nl = getXpathApi().selectNodeList(document, xPath);
if (nl != null)
for (int i = 0; i< nl.getLength(); i++) {
Node node = doc.importNode(nl.item(i), true);
Element elt = doc.getDocumentElement();
if (node.getNodeType() == Node.ELEMENT_NODE) {
elt.appendChild(node);
}
if (node.getNodeType() == Node.TEXT_NODE) {
elt.appendChild(node);
}
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
elt.setAttribute(node.getNodeName() + "_" + i, node.getNodeValue());
}
}
return doc;
} catch (TransformerException e) {
ConvertigoPlugin.logWarning("Error for xpath : '" + xPath + "'\r " + e.getMessage());
return null;
}
}
示例12: 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.
*
* @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.
*/
public 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 :
buf.append(node.getNodeValue());
break;
case Node.ATTRIBUTE_NODE :
buf.append(node.getNodeValue());
break;
case Node.PROCESSING_INSTRUCTION_NODE :
// warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
break;
default :
// ignore
break;
}
}
示例13: processAttributes
private void processAttributes(Node xmlNode, Map<String, Object> nodeObject) {
NamedNodeMap attributesMap = xmlNode.getAttributes();
int attrCount = attributesMap.getLength();
for (int attrIndex = 0; attrIndex < attrCount; attrIndex++) {
Node attributeNode = attributesMap.item(attrIndex);
if (attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
String prefix = attributeNode.getPrefix() != null ? attributeNode.getPrefix() : "";
nodeObject.put("$" + prefix + attributeNode.getNodeName(), attributeNode.getNodeValue());
}
}
}
示例14: saveEnclosingAttr
/**
* NON-DOM INTERNAL: Pre-mutation context check, in
* preparation for later generating DOMAttrModified events.
* Determines whether this node is within an Attr
* @param node node to get enclosing attribute for
* @return either a description of that Attr, or null if none such.
*/
protected void saveEnclosingAttr(NodeImpl node) {
savedEnclosingAttr = null;
// MUTATION PREPROCESSING AND PRE-EVENTS:
// If we're within the scope of an Attr and DOMAttrModified
// was requested, we need to preserve its previous value for
// that event.
LCount lc = LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);
if (lc.total > 0) {
NodeImpl eventAncestor = node;
while (true) {
if (eventAncestor == null)
return;
int type = eventAncestor.getNodeType();
if (type == Node.ATTRIBUTE_NODE) {
EnclosingAttr retval = new EnclosingAttr();
retval.node = (AttrImpl) eventAncestor;
retval.oldvalue = retval.node.getNodeValue();
savedEnclosingAttr = retval;
return;
}
else if (type == Node.ENTITY_REFERENCE_NODE)
eventAncestor = eventAncestor.parentNode();
else if (type == Node.TEXT_NODE)
eventAncestor = eventAncestor.parentNode();
else
return;
// Any other parent means we're not in an Attr
}
}
}
示例15: getXpathData
public static Document getXpathData(Document document, String xPath) {
if (document == null) {
return null;
}
if (xPath == null) {
return null;
}
try {
Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
Element root = (Element) doc.createElement("root");
doc.appendChild(root);
NodeList nl = new TwsCachedXPathAPI().selectNodeList(document, xPath);
if (nl != null)
for (int i = 0; i < nl.getLength(); i++) {
Node node = doc.importNode(nl.item(i), true);
Element elt = doc.getDocumentElement();
if (node.getNodeType() == Node.ELEMENT_NODE) {
elt.appendChild(node);
}
if (node.getNodeType() == Node.TEXT_NODE) {
elt.appendChild(node);
}
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
elt.setAttribute(node.getNodeName() + "_" + i, node.getNodeValue());
}
}
return doc;
}
catch (TransformerException e) {
//ConvertigoPlugin.logWarning("Error for xpath : '" + xPath + "'\r " + e.getMessage());
return null;
}
}