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


Java Node.hasChildNodes方法代碼示例

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


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

示例1: GetNodeText

import org.w3c.dom.Node; //導入方法依賴的package包/類
static public String GetNodeText(Node parent) {
	String s;
	StringBuffer value;
	NodeList nodes;
	Node node;
	int n;

	value=new StringBuffer(""); 
	if (parent.hasChildNodes()) {
		nodes=parent.getChildNodes();
		for(n=0;n<nodes.getLength();n++) { 
			node=nodes.item(n);
			if (node.getNodeType()==Node.TEXT_NODE)
				value.append(node.getNodeValue());
			if (node.hasChildNodes())
				value.append(GetNodeText(node));
		}
	} else {
		s=parent.getNodeValue();
		if (s!=null) return s; else return "";
	}
	return value.toString();
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:24,代碼來源:XmlHelper.java

示例2: parseDocument

import org.w3c.dom.Node; //導入方法依賴的package包/類
private static Flag parseDocument(Node node) throws IOException {
	String type = node.getNodeName();
	if (type.equalsIgnoreCase("#document")) {
		for (Node child : getChildren(node)) {
			String ctype = child.getNodeName();
			if (ctype.equalsIgnoreCase("flag")) {
				if (child.hasAttributes() || child.hasChildNodes()) {
					return parseFlag(child);
				}
			} else {
				throw new IOException("Unknown element: " + ctype);
			}
		}
		throw new IOException("Empty document.");
	} else {
		throw new IOException("Unknown element: " + type);
	}
}
 
開發者ID:kreativekorp,項目名稱:vexillo,代碼行數:19,代碼來源:FlagParser.java

示例3: loadIniSettings

import org.w3c.dom.Node; //導入方法依賴的package包/類
public static  LinkedList<Map<String,String>> loadIniSettings(String filePath){ 
	LinkedList<Map<String,String>> xmlExtrakt = new LinkedList<Map<String,String>>();
	Document doc= getXmlDocument(filePath);	
	Map<String,String> tagsAndContents = new HashMap<String,String>();

	Node lastDir = getElementByTagName(doc,"LASTDIR" );
	if (lastDir!=null &&lastDir.hasChildNodes()){
		String lastDirLocator = lastDir.getFirstChild().getNodeValue();
		if (lastDirLocator!=null && lastDirLocator.trim()!=null){
		tagsAndContents.put("LASTDIR",lastDirLocator);
		xmlExtrakt.add(tagsAndContents);
		}
	}
	
	Node warnLvlNode = getElementByTagName(doc,"WARNINGLEVEL" );
	if (warnLvlNode!=null && warnLvlNode.hasChildNodes()){
		String warnLvl = warnLvlNode.getFirstChild().getNodeValue();
		if (warnLvl!=null && warnLvl.trim()!=null){
		tagsAndContents.put("WARNINGLEVEL",warnLvl);
		xmlExtrakt.add(tagsAndContents);
		}
	}
	
	//System.out.println(xmlExtrakt);
    return xmlExtrakt;
}
 
開發者ID:RaduMarcel,項目名稱:EspressoViews,代碼行數:27,代碼來源:QueryDefinitionParser.java

示例4: storeIniSettings

import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void storeIniSettings( String iniFile, String iniSettingName,String iniSettingValue){
	Document doc= getXmlDocument((new File (iniFile)).getAbsolutePath() );	
	Node lastDir = getElementByTagName(doc,iniSettingName );
	if (lastDir==null ){//neues ini setting tag kreieren
		Element neuesElement = doc.createElement(iniSettingName);
		neuesElement.appendChild(doc.createTextNode(iniSettingValue));
		getElementByTagName(doc,"ROOT" ).appendChild(neuesElement);
	}
	else 
		if (lastDir.hasChildNodes()){//altes ini setting �berschreiben
			lastDir.getFirstChild().setTextContent(iniSettingValue); 
		}
	if (lastDir!= null && !lastDir.hasChildNodes()){//ini setting im leeren tag schreiben 
		lastDir.appendChild(doc.createTextNode(iniSettingValue)); 
	}
	storeXmlDocToFile(iniFile, doc);	
}
 
開發者ID:RaduMarcel,項目名稱:EspressoViews,代碼行數:18,代碼來源:QueryDefinitionParser.java

示例5: importNode

import org.w3c.dom.Node; //導入方法依賴的package包/類
@Override
public org.w3c.dom.Node importNode(Node importedNode, boolean deep)
    throws DOMException {
    Node domNode = getDomNode(importedNode);
    final Node newNode = document.importNode(domNode, deep);

    if (importedNode instanceof javax.xml.soap.Node) {
        Node newSoapNode = createSoapNode(importedNode.getClass(), newNode);
        newNode.setUserData(SAAJ_NODE, newSoapNode, null);
        if (deep && importedNode.hasChildNodes()) {
            NodeList childNodes = importedNode.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                registerChildNodes(childNodes.item(i), deep);
            }
        }
        return newSoapNode;
    }

    registerChildNodes(newNode, deep);
    return findIfPresent(newNode);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:SOAPDocumentImpl.java

示例6: getNormalizedText

import org.w3c.dom.Node; //導入方法依賴的package包/類
public static String getNormalizedText(Node node) {
	String res = "";
	if (node.hasChildNodes()) {
		NodeList nl = node.getChildNodes();
		for (int i = 0; i < nl.getLength(); i++) {
			if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
				res += nl.item(i).getNodeValue();
			} else {
				// ignore <SCRIPT> nodes ...
				if (!nl.item(i).getNodeName().equalsIgnoreCase("script"))
					res += getNormalizedText(nl.item(i));
			}
		}
	}
	return res;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:17,代碼來源:XMLUtils.java

示例7: findChildrenNodes

import org.w3c.dom.Node; //導入方法依賴的package包/類
private List<Node> findChildrenNodes(Node node) {
    List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < node.getChildNodes().getLength(); i++) {
        Node n = node.getChildNodes().item(i);
        nodes.add(n);
        if (n.hasChildNodes()) {
            nodes.addAll(findChildrenNodes(n));
        }
    }
    return nodes;
}
 
開發者ID:Scrumplex,項目名稱:FXMLHelper,代碼行數:12,代碼來源:ControllerGeneratorAction.java

示例8: if

import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
 *
 * @param listVector
 * @param tempNode
 * @param tagname
 * @param isTagNameWildCard
 *
 *
 * Private method to be used for recursive iterations to obtain elements by tag name.
 */
private final void traverseChildren
(
  Vector listVector,
  Node tempNode,
  String tagname,
  boolean isTagNameWildCard) {
  if (tempNode == null)
  {
    return;
  }
  else
  {
    if (tempNode.getNodeType() == DTM.ELEMENT_NODE
          && (isTagNameWildCard || tempNode.getNodeName().equals(tagname)))
    {
      listVector.add(tempNode);
    }
    if(tempNode.hasChildNodes())
    {
      NodeList nodeList = tempNode.getChildNodes();
      for (int i = 0; i < nodeList.getLength(); i++)
      {
        traverseChildren(listVector, nodeList.item(i), tagname,
                         isTagNameWildCard);
      }
    }
  }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:39,代碼來源:DTMNodeProxy.java

示例9: showMeTheDoc

import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void showMeTheDoc(Node node, int level ){
	//if (node.getNodeType()==1)
	if (node.hasAttributes()) System.out.println(node.getAttributes());
    System.out.println("Level "+level+DisplayData.multiplyChars(' ',(level-1)*10)+" Der Knoten "+node.getNodeName()
    		//+" mit dem Inhalt "+" Node Text Content: "+node.getTextContent()
    		+" und mit dem Node Type "+node.getNodeType()+" und node value: "+node.getNodeValue()
    		+" hat "+node.getChildNodes().getLength()+" Kinder "
    		);
    	if (node.hasChildNodes()){
			 NodeList children=  node.getChildNodes();
		 for (int t = 0;t<children.getLength();t++){
			showMeTheDoc(children.item(t), level+1);
		 }
	   }
}
 
開發者ID:RaduMarcel,項目名稱:EspressoViews,代碼行數:16,代碼來源:QueryDefinitionParser.java

示例10: getChildNode

import org.w3c.dom.Node; //導入方法依賴的package包/類
private Node getChildNode(Node node, String childName) {
    Node childNode = null;
    if(node.hasChildNodes()) {
        NodeList childNodes = node.getChildNodes();
        int length = childNodes.getLength();
        for(int i = 0; i < length; i++) {
            Node item = childNodes.item(i);
            if(item.getNodeName().equals(childName)) {
                childNode = item;
                break;
            }
        }
    }
    return childNode;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TIFFImageMetadata.java

示例11: removeAll

import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void removeAll(Node node) {
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        Node n = list.item(i);
        if (n.hasChildNodes()) {
            removeAll(n);
            node.removeChild(n);
        } else {
            node.removeChild(n);
        }
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:13,代碼來源:XMLOperation.java

示例12: person

import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
 * evaluate tag contents and swap 1st and 2nd person pronouns
 * implements {@code <person>} tag
 *
 * @param node     current XML parse node
 * @param ps       AIML parse state
 * @return         sentence with pronouns swapped
 */
private static String person(Node node, ParseState ps) {
    String result;
    if (node.hasChildNodes())
      result = evalTagContent(node, ps, null);
    else result = ps.starBindings.inputStars.star(0);   // for <person/>
    result = " "+result+" ";
    result = ps.chatSession.bot.preProcessor.person(result);
    return result.trim();
}
 
開發者ID:Suhas010,項目名稱:Artificial-Intelligent-chat-bot-,代碼行數:18,代碼來源:AIMLProcessor.java

示例13: cloneNodeWithUserData

import org.w3c.dom.Node; //導入方法依賴的package包/類
private static Node cloneNodeWithUserData(Node node, boolean recurse) {
	if (node != null) {
		Object node_output = node.getUserData(Step.NODE_USERDATA_OUTPUT);

		Node clonedNode = node.cloneNode(false);
		clonedNode.setUserData(Step.NODE_USERDATA_OUTPUT, node_output, null);
		
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			// attributes
			NamedNodeMap attributeMap = clonedNode.getAttributes();
			for (int i=0; i< attributeMap.getLength(); i++) {
				Node clonedAttribute = attributeMap.item(i);
				String attr_name = clonedAttribute.getNodeName();
				Object attr_output = ((Element)node).getAttributeNode(attr_name).getUserData(Step.NODE_USERDATA_OUTPUT);
				clonedAttribute.setUserData(Step.NODE_USERDATA_OUTPUT, attr_output, null);
			}
			
			// recurse on element child nodes only
			if (recurse && node.hasChildNodes()) {
				NodeList list = node.getChildNodes();
				for (int i=0; i<list.getLength(); i++) {
					Node clonedChild = cloneNodeWithUserData(list.item(i), recurse);
					if (clonedChild != null) {
						clonedNode.appendChild(clonedChild);
					}
				}
			}
		}
		
		return clonedNode;
	}
	return null;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:34,代碼來源:Sequence.java

示例14: if

import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
 *
 * @param listVector
 * @param tempNode
 * @param namespaceURI
 * @param localname
 * @param isNamespaceURIWildCard
 * @param isLocalNameWildCard
 *
 * Private method to be used for recursive iterations to obtain elements by tag name
 * and namespaceURI.
 */
private final void traverseChildren
(
 Vector listVector,
 Node tempNode,
 String namespaceURI,
 String localname,
 boolean isNamespaceURIWildCard,
 boolean isLocalNameWildCard)
 {
  if (tempNode == null)
  {
    return;
  }
  else
  {
    if (tempNode.getNodeType() == DTM.ELEMENT_NODE
            && (isLocalNameWildCard
                    || tempNode.getLocalName().equals(localname)))
    {
      String nsURI = tempNode.getNamespaceURI();
      if ((namespaceURI == null && nsURI == null)
             || isNamespaceURIWildCard
             || (namespaceURI != null && namespaceURI.equals(nsURI)))
      {
        listVector.add(tempNode);
      }
    }
    if(tempNode.hasChildNodes())
    {
      NodeList nl = tempNode.getChildNodes();
      for(int i = 0; i < nl.getLength(); i++)
      {
        traverseChildren(listVector, nl.item(i), namespaceURI, localname,
                         isNamespaceURIWildCard, isLocalNameWildCard);
      }
    }
  }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:51,代碼來源:DTMNodeProxy.java

示例15: getLastChild

import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Internal function.
 *  Return the last child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getLastChild(Node node) {

    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;

    Node newNode = node.getLastChild();
    if (newNode == null)  return null;

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node lChild = getLastChild(newNode);
        if (lChild == null) {
            return getPreviousSibling(newNode, node);
        }
        return lChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, node);
    }


}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:39,代碼來源:TreeWalkerImpl.java


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