当前位置: 首页>>代码示例>>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;未经允许,请勿转载。