當前位置: 首頁>>代碼示例>>Java>>正文


Java NamedNodeMap.getLength方法代碼示例

本文整理匯總了Java中org.w3c.dom.NamedNodeMap.getLength方法的典型用法代碼示例。如果您正苦於以下問題:Java NamedNodeMap.getLength方法的具體用法?Java NamedNodeMap.getLength怎麽用?Java NamedNodeMap.getLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.w3c.dom.NamedNodeMap的用法示例。


在下文中一共展示了NamedNodeMap.getLength方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: traverse

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
public static void traverse(Node node, int depth) {
    indent(depth);
    System.out.print("<"+node.getNodeName());

    if (node.hasAttributes()) {
        NamedNodeMap attrs = node.getAttributes();
        for (int i=0; i<attrs.getLength(); i++) {
            System.out.print("  "+((Attr)attrs.item(i)).getName()+"=\""+((Attr)attrs.item(i)).getValue()+"\"");
        }
    }

    if (node.hasChildNodes()) {
        System.out.println(">");
        depth+=4;
        for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            traverse(child, depth);
        }
        depth-=4;
        indent(depth);
        System.out.println("</"+node.getNodeName()+">");
    }
    else {
        System.out.println("/>");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:SchemaDOM.java

示例2: displayMetadata

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
static void displayMetadata(Node node, int level) {
    for (int i = 0; i < level; i++) System.out.print("  ");
    System.out.print("<" + node.getNodeName());
    NamedNodeMap map = node.getAttributes();
    if (map != null) { // print attribute values
        int length = map.getLength();
        for (int i = 0; i < length; i++) {
            Node attr = map.item(i);
            System.out.print(" " + attr.getNodeName() +
                             "=\"" + attr.getNodeValue() + "\"");
        }
    }

    Node child = node.getFirstChild();
    if (child != null) {
        System.out.println(">"); // close current tag
        while (child != null) { // emit child tags recursively
            displayMetadata(child, level + 1);
            child = child.getNextSibling();
        }
        for (int i = 0; i < level; i++) System.out.print("  ");
        System.out.println("</" + node.getNodeName() + ">");
    } else {
        System.out.println("/>");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:MagentaEXIFTest.java

示例3: allocatePrefix

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/**
 * Declares a new prefix on the given element and associates it
 * with the specified namespace URI.
 * <p>
 * Note that this method doesn't use the default namespace
 * even if it can.
 */
private String allocatePrefix( Element e, String nsUri ) {
    // look for existing namespaces.
    NamedNodeMap atts = e.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( Const.XMLNS_URI.equals(a.getNamespaceURI()) ) {
            if( a.getName().indexOf(':')==-1 )  continue;

            if( a.getValue().equals(nsUri) )
                return a.getLocalName();    // found one
        }
    }

    // none found. allocate new.
    while(true) {
        String prefix = "p"+(int)(Math.random()*1000000)+'_';
        if(e.getAttributeNodeNS(Const.XMLNS_URI,prefix)!=null)
            continue;   // this prefix is already allocated.

        e.setAttributeNS(Const.XMLNS_URI,"xmlns:"+prefix,nsUri);
        return prefix;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:31,代碼來源:Internalizer.java

示例4: checkAttributesEqual

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
protected boolean checkAttributesEqual(final Element p1, final Element p2) {
    if (p1 == null || p2 == null) return false;
    NamedNodeMap nm1 = p1.getAttributes();
    NamedNodeMap nm2 = p2.getAttributes();
    //if( nm1.getLength() != nm2.getLength() ) return false;

    for ( int i = 0; i < nm1.getLength(); i++ ) {
        Node attr1 = (Node) nm1.item(i);
        if(attr1.getNodeName().startsWith("xmlns"))
            continue;
        Node attr2 = (Node) nm2.getNamedItem(attr1.getNodeName());
        if ( attr2 == null ) return false;
        if(nm2.item(i) != attr2) return false;
        if(!attr1.getNodeValue().equals(attr2.getNodeValue()))
            return false;
    }
    return true;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:XDMUtil.java

示例5: JFIFThumbUncompressed

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
JFIFThumbUncompressed(Node node, String name)
    throws IIOInvalidTreeException {

    thumbWidth = 0;
    thumbHeight = 0;
    this.name = name;
    NamedNodeMap attrs = node.getAttributes();
    int count = attrs.getLength();
    if (count > 2) {
        throw new IIOInvalidTreeException
            (name +" node cannot have > 2 attributes", node);
    }
    if (count != 0) {
        int value = getAttributeValue(node, attrs, "thumbWidth",
                                      0, 255, false);
        thumbWidth = (value != -1) ? value : thumbWidth;
        value = getAttributeValue(node, attrs, "thumbHeight",
                                  0, 255, false);
        thumbHeight = (value != -1) ? value : thumbHeight;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:JFIFMarkerSegment.java

示例6: initializeFromXml

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
public void initializeFromXml(Element el)
    throws AllocationConfigurationException {
  boolean create = true;
  NamedNodeMap attributes = el.getAttributes();
  Map<String, String> args = new HashMap<String, String>();
  for (int i = 0; i < attributes.getLength(); i++) {
    Node node = attributes.item(i);
    String key = node.getNodeName();
    String value = node.getNodeValue();
    if (key.equals("create")) {
      create = Boolean.parseBoolean(value);
    } else {
      args.put(key, value);
    }
  }
  initialize(create, args);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:QueuePlacementRule.java

示例7: findAttributes

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
@Override
public List<Attr> findAttributes(Element element) {
    List<Attr> found = null;
    final String expectedName = getLocalName();
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        if (attribute.getLocalName().equals(expectedName)) {
            if (found == null) {
                found = new ArrayList<>();
            }
            found.add((Attr)attribute);
        }
    }
    return (found != null) ? found : Collections.emptyList();
}
 
開發者ID:i49,項目名稱:cascade,代碼行數:17,代碼來源:AttributeNameMatcher.java

示例8: copyNodeAndAttributes

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
private static final org.w3c.dom.Element copyNodeAndAttributes(Node node) {
	org.w3c.dom.Element result = document.createElement(node.getNodeName());
	NamedNodeMap attributes = node.getAttributes();
	for (int i = 0; i < attributes.getLength(); ++i) {
		Node a = attributes.item(i);
		String name = a.getNodeName();
		String value = a.getNodeValue();
		result.setAttribute(name, value);
	}
	return result;
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:12,代碼來源:XMLReader.java

示例9: concatAttributes

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/**
 * Retrieve and concatenate a node's attribute name/value pairs
 * 
 * @param nextNode
 *            the next node in the XML tree to be parsed.
 * @param resultText
 *            the concatenated result text.
 * 
 * @return the concatenated result text.
 */
private String concatAttributes(Node nextNode, String resultText) {
	try {
		// process element attributes
		if (nextNode.getAttributes() != null) {
			NamedNodeMap attributes = nextNode.getAttributes();
			String attributesBlock = "";
			if (attributes.getNamedItem("name") != null) { // name attribute
															// first.
				attributesBlock = attributesBlock + "name="
						+ attributes.getNamedItem("name").getNodeValue();
				if (attributes.getLength() > 1) {
					attributesBlock = attributesBlock + ", ";
				}
			}
			// Clean up DP response namespace declaration.
			for (int i = 0; i < attributes.getLength(); i++) {
				if (!attributes.item(i).getNodeValue()
						.contains("soap-envelope")
						&& (attributes.item(i).getLocalName() != "name")) {
					attributesBlock = attributesBlock
							+ attributes.item(i).getLocalName() + "="
							+ attributes.item(i).getNodeValue();
					if (i != attributes.getLength() - 1) {
						attributesBlock = attributesBlock + ", ";
					}
				}
			}
			if (attributesBlock != "") {
				resultText = resultText + ", " + attributesBlock;
			}
		}
	} catch (NullPointerException ex) {
		return resultText;
	}
	return resultText;
}
 
開發者ID:mqsysadmin,項目名稱:dpdirect,代碼行數:47,代碼來源:ResponseParser.java

示例10: RelationMetadata

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
protected RelationMetadata(Element element) {
	logger.debug("Constructor - entry");

	NodeList nodeList = element.getChildNodes();
	for (int n = 0; n < nodeList.getLength(); n++) {
		Node node = nodeList.item(n);
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			Element childElement = (Element) node;
			if ("METADATA".equals(childElement.getNodeName())) {
				setMetadata(new Metadata(childElement));
			} else if ("ATTRIBUTE".equals(childElement.getNodeName())) {
				setAttribute(new Attribute(childElement));
			} else {
				logger.trace("Unrecognized child node: '" + childElement.getNodeName() + "'");
			}
		} else if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue() != null) && (node.getNodeValue().trim().length() > 0)) {
			logger.trace("Unexpected text node (" + this.getClass().getName() + "): '" + node.getNodeValue() + "'");
		}
	}

	NamedNodeMap namedNodeMap = element.getAttributes();
	if (namedNodeMap != null) {
		for (int a = 0; a < namedNodeMap.getLength(); a++) {
			Attr attributeNode = (Attr) namedNodeMap.item(a);
			logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "'");
		}
	}

	logger.debug("Constructor - exit");
}
 
開發者ID:Smartlogic-Semaphore-Limited,項目名稱:Java-APIs,代碼行數:31,代碼來源:RelationMetadata.java

示例11: build

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
public void build(Element e) {
  if (e != null) {
    final NamedNodeMap attributes = e.getAttributes();
    for (int i = 0; i < attributes.getLength(); ++i) {
      final Attr att = (Attr) attributes.item(i);

      // Old versions of VASSAL (pre-2.9?) wrote "Retire" as the
      // icon filename for the retireButton, even when no such
      // image existed in the archive. This test blocks irritating
      // errors due to nonexistent "Retire" images, by ignoring
      // the buttonIcon attribute when the value is "Retire" but
      // no such image can be found in the archive.
      if ("buttonIcon".equals(att.getName()) && //$NON-NLS-1$
          "Retire".equals(att.getValue())) { //$NON-NLS-1$
        try {
          GameModule.getGameModule()
                    .getDataArchive()
                    .getInputStream(DataArchive.IMAGE_DIR + att.getValue());
        }
        catch (IOException ex) {
          continue;
        }
      }

      retireButton.setAttribute(att.getName(), att.getValue());
      Localization.getInstance()
                  .saveTranslatableAttribute(this, att.getName(),
                                                   att.getValue());
    }

    final NodeList n = e.getElementsByTagName("*"); //$NON-NLS-1$
    sides.clear();
    for (int i = 0; i < n.getLength(); ++i) {
      final Element el = (Element) n.item(i);
      sides.add(Builder.getText(el));
    }
    Localization.getInstance()
                .saveTranslatableAttribute(this, SIDES, getSidesAsString());
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:41,代碼來源:PlayerRoster.java

示例12: NoteType

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
protected NoteType(Element element) {
	logger.debug("Constructor - entry");

	NodeList nodeList = element.getChildNodes();
	for (int n = 0; n < nodeList.getLength(); n++) {
		Node node = nodeList.item(n);
		if (node.getNodeType() == Node.ELEMENT_NODE) {
	    	logger.trace("Unrecognized child node: '" + element.getNodeName() + "'");
		} else if (node.getNodeType() == Node.TEXT_NODE) {
			this.setName(node.getNodeValue());
		}
	}

	NamedNodeMap namedNodeMap = element.getAttributes();
	if (namedNodeMap != null) {
		for (int a = 0; a < namedNodeMap.getLength(); a++) {
			Attr attributeNode = (Attr) namedNodeMap.item(a);
			if ("ID".equals(attributeNode.getName())) {
				setId(attributeNode.getValue());
			} else if ("NAME".equals(attributeNode.getName())) {
				setName(attributeNode.getValue());
			} else {
				logger.trace("Unrecognized attribute: '" + attributeNode.getName() + "'");
			}
		}

	}
	logger.debug("Constructor - exit");
}
 
開發者ID:Smartlogic-Semaphore-Limited,項目名稱:Java-APIs,代碼行數:30,代碼來源:NoteType.java

示例13: processAttributes

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
private void processAttributes(NamedNodeMap attrMap) {
    final int attrCount = attrMap.getLength();
    fAttributes.removeAllAttributes();
    for (int i = 0; i < attrCount; ++i) {
        Attr attr = (Attr) attrMap.item(i);
        String value = attr.getValue();
        if (value == null) {
            value = XMLSymbols.EMPTY_STRING;
        }
        fillQName(fAttributeQName, attr);
        // REVISIT: Assuming all attributes are of type CDATA. The actual type may not matter. -- mrglavas
        fAttributes.addAttributeNS(fAttributeQName, XMLSymbols.fCDATASymbol, value);
        fAttributes.setSpecified(i, attr.getSpecified());
        // REVISIT: Should we be looking at non-namespace attributes
        // for additional mappings? Should we detect illegal namespace
        // declarations and exclude them from the context? -- mrglavas
        if (fAttributeQName.uri == NamespaceContext.XMLNS_URI) {
            // process namespace attribute
            if (fAttributeQName.prefix == XMLSymbols.PREFIX_XMLNS) {
                fNamespaceContext.declarePrefix(fAttributeQName.localpart, value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
            }
            else {
                fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:DOMValidatorHelper.java

示例14: loadAttributes

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
public static Map<String, Object> loadAttributes(Element e) {
    Map<String, Object> map = new HashMap<String, Object>();
    NamedNodeMap nm = e.getAttributes();
    for (int j = 0; j < nm.getLength(); j++) {
        Node n = nm.item(j);
        if (n instanceof Attr) {
            Attr attr = (Attr) n;
            map.put(attr.getName(), attr.getNodeValue());
        }
    }
    return map;
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:13,代碼來源:ConfigUtil.java

示例15: endPrefixMapping

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
private void endPrefixMapping(ContentHandler contentHandler, NamedNodeMap attrs, String excludePrefix) throws SAXException {
    if(attrs == null)
        return;
    for(int i=0; i < attrs.getLength();i++) {
        Attr a = (Attr)attrs.item(i);
        //check if attr is ns declaration
        if("xmlns".equals(a.getPrefix()) || "xmlns".equals(a.getLocalName())) {
            if(!fixNull(a.getPrefix()).equals(excludePrefix)) {
                contentHandler.endPrefixMapping(fixNull(a.getPrefix()));
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:SAAJMessage.java


注:本文中的org.w3c.dom.NamedNodeMap.getLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。