Java Code Examples for org.w3c.dom.Node.hasAttributes()

The following are Jave code examples for showing how to use hasAttributes() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: vexillo   File: FlagParser.java   Source Code and License Vote up 6 votes
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);
	}
}
 
Example 2
Project: Artificial-Intelligent-chat-bot-   File: AIMLProcessor.java   Source Code and License Vote up 6 votes
/**
   * return a string of unevaluated XML.      When the AIML parser
   * encounters an unrecognized XML tag, it simply passes through the
   * tag in XML form.  For example, if the response contains HTML
   * markup, the HTML is passed to the requesting process.    However if that
   * markup contains AIML tags, those tags are evaluated and the parser
   * builds the result.
   *
   * @param node           current parse node.
   * @param ps             current parse state.
   * @return               the unevaluated XML string
   */
  private static String unevaluatedXML(String resultIn, Node node, ParseState ps) {
      //MagicBooleans.trace("AIMLProcessor.unevaluatedXML(resultIn: " + resultIn + ", node: " + node + ", ps: " + ps);
      String nodeName = node.getNodeName();
      //MagicBooleans.trace("in AIMLProcessor.unevaluatedXML(), nodeName: " + nodeName);
      String attributes = "";
      if (node.hasAttributes()) {
          NamedNodeMap XMLAttributes = node.getAttributes();
          for(int i=0; i < XMLAttributes.getLength(); i++)

          {
              attributes += " "+XMLAttributes.item(i).getNodeName()+"=\""+XMLAttributes.item(i).getNodeValue()+"\"";
          }
      }
     // String contents = evalTagContent(node, ps, null);
String result = "<"+nodeName+attributes+"/>";
      if (! resultIn.equals(""))
	result = "<"+nodeName+attributes+">"+resultIn+"</"+nodeName+">";
      //MagicBooleans.trace("in AIMLProcessor.unevaluatedXML() returning: " + result);
return result;
  }
 
Example 3
Project: karate   File: XmlUtils.java   Source Code and License Vote up 6 votes
public static Object toObject(Node node) {
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        node = node.getFirstChild();
        Map<String, Object> map = new LinkedHashMap<>(1);
        map.put(node.getNodeName(), toObject(node));
        return map;
    }
    Object value = getElementAsObject(node);
    if (node.hasAttributes()) {
        Map<String, Object> wrapper = new LinkedHashMap<>(2);
        wrapper.put("_", value);
        wrapper.put("@", getAttributes(node));
        return wrapper;
    } else {
        return value;
    }
}
 
Example 4
Project: OpenJSharp   File: SchemaDOM.java   Source Code and License Vote up 6 votes
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("/>");
    }
}
 
Example 5
Project: openjdk-jdk10   File: SchemaDOM.java   Source Code and License Vote up 6 votes
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("/>");
    }
}
 
Example 6
Project: EspressoViews   File: QueryDefinitionParser.java   Source Code and License Vote up 5 votes
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);
		 }
	   }
}
 
Example 7
Project: EspressoViews   File: QueryDefinitionParser.java   Source Code and License Vote up 5 votes
private static void extractQueryDefinition(Node node, int level, Map<String,String> tagsAndContents, List<Map<String,String>> xmlExtrakt, boolean definitionBegins, String mainXmlTag) {
    //System.out.println(level+"\n Node Text Content: "+node.getTextContent());
 if (node.hasChildNodes()){
  NodeList children = node.getChildNodes();
 //System.out.println(DisplayData.multiplyChars(' ',(level-1)*10)+node.getNodeName()+" hat "+children.getLength()+" Kinder ");
 if (node.getNodeName().toUpperCase().equals(mainXmlTag) && children.getLength()>1){
	 definitionBegins=true; 
	 if (tagsAndContents.size()>0) {
		 xmlExtrakt.add(new HashMap<String,String>(tagsAndContents));
		 tagsAndContents.clear();
	 }
	 if (node.hasAttributes() ){
		 for (int t=0;t<node.getAttributes().getLength();t++ ){
			 tagsAndContents.put(node.getAttributes().item(t).getNodeName().toUpperCase(), node.getAttributes().item(t).getNodeValue().toUpperCase());
		//	 System.out.println(node.getAttributes().item(t).getNodeName()+" "+node.getAttributes().item(t).getNodeValue()); 
		 }
	 }
 }	 
 if (children.getLength()==1 && definitionBegins && !node.getNodeName().toUpperCase().equals(mainXmlTag)) {
	 //System.out.println(DisplayData.multiplyChars(' ',(level-1)*10)+"Content  "+node.getTextContent()+"\n");
	 tagsAndContents.put(node.getNodeName().toUpperCase(), node.getTextContent().trim());
 }
 for (int t = 0;t<children.getLength();t++){
	 extractQueryDefinition(children.item(t), level+1,tagsAndContents,xmlExtrakt,definitionBegins,mainXmlTag);
 }
  }
}
 
Example 8
Project: Artificial-Intelligent-chat-bot-   File: JapaneseUtils.java   Source Code and License Vote up 5 votes
private static String unevaluatedXML(String result, Node node) {
    String nodeName = node.getNodeName();
    String attributes = "";
    if (node.hasAttributes()) {
        NamedNodeMap XMLAttributes = node.getAttributes();
        for(int i=0; i < XMLAttributes.getLength(); i++)

        {
            attributes += " "+XMLAttributes.item(i).getNodeName()+"=\""+XMLAttributes.item(i).getNodeValue()+"\"";
        }
    }
    if (result.equals(""))
        return " <"+nodeName+attributes+"/> ";
    else return " <"+nodeName+attributes+">"+result+"</"+nodeName+"> ";   // add spaces
}
 
Example 9
Project: oscm   File: MigrationBillingResultDecimalPlace.java   Source Code and License Vote up 5 votes
private void updateAttributeValue(Node node, String attName,
        int decimalPlacesSetting) {
    if (node.hasAttributes()
            && !"NumberOfOccurrence".equals(node.getNodeName())
            && !"ParameterValue".equals(node.getNodeName())) {
        Node attribute = node.getAttributes().getNamedItem(attName);
        if (attribute != null) {
            String priceValue = attribute.getNodeValue();
            if (priceValue != null && priceValue.length() > 0) {
                attribute.setNodeValue(getConvertedPrice(priceValue,
                        decimalPlacesSetting));
            }
        }
    }
}
 
Example 10
Project: Equella   File: PropBagEx.java   Source Code and License Vote up 5 votes
public boolean hasAttributes(final String szPath)
{
	ensureRoot();
	Node oNode = getNodeHelper(szPath, false, false);
	if( oNode == null )
	{
		return false;
	}
	return oNode.hasAttributes();
}
 
Example 11
Project: OpenJSharp   File: JPEGMetadata.java   Source Code and License Vote up 5 votes
private boolean wantAlpha(Node transparency) {
    boolean returnValue = false;
    Node alpha = transparency.getFirstChild();  // Alpha must be first if present
    if (alpha.getNodeName().equals("Alpha")) {
        if (alpha.hasAttributes()) {
            String value =
                alpha.getAttributes().getNamedItem("value").getNodeValue();
            if (!value.equals("none")) {
                returnValue = true;
            }
        }
    }
    transparencyDone = true;
    return returnValue;
}
 
Example 12
Project: jdk8u-jdk   File: JPEGMetadata.java   Source Code and License Vote up 5 votes
private boolean wantAlpha(Node transparency) {
    boolean returnValue = false;
    Node alpha = transparency.getFirstChild();  // Alpha must be first if present
    if (alpha.getNodeName().equals("Alpha")) {
        if (alpha.hasAttributes()) {
            String value =
                alpha.getAttributes().getNamedItem("value").getNodeValue();
            if (!value.equals("none")) {
                returnValue = true;
            }
        }
    }
    transparencyDone = true;
    return returnValue;
}
 
Example 13
Project: openjdk-jdk10   File: JPEGMetadata.java   Source Code and License Vote up 5 votes
private boolean wantAlpha(Node transparency) {
    boolean returnValue = false;
    Node alpha = transparency.getFirstChild();  // Alpha must be first if present
    if (alpha.getNodeName().equals("Alpha")) {
        if (alpha.hasAttributes()) {
            String value =
                alpha.getAttributes().getNamedItem("value").getNodeValue();
            if (!value.equals("none")) {
                returnValue = true;
            }
        }
    }
    transparencyDone = true;
    return returnValue;
}
 
Example 14
Project: OCCI-Studio   File: RegenerateConnectorAction.java   Source Code and License Vote up 4 votes
private String getExtensionFactoryClass(IFile pluginXML) {
	try {
		IPath location = pluginXML.getLocation();
		if (location != null) {
			File file = location.toFile();

			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			Document doc = dBuilder.parse(file);

			if (doc.hasChildNodes()) {
				NodeList nodeList = doc.getChildNodes();
				for (int count = 0; count < nodeList.getLength(); count++) {
					Node tempNode = nodeList.item(count);
					if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
						if (tempNode.getNodeName().equals("plugin")) {
							for (int count1 = 0; count1 < tempNode.getChildNodes().getLength(); count1++) {
								Node tempNode1 = tempNode.getChildNodes().item(count1);
								if (tempNode1.getNodeType() == Node.ELEMENT_NODE) {
									if (tempNode1.getNodeName().equals("extension")) {
										for (int count11 = 0; count11 < tempNode1.getChildNodes()
												.getLength(); count11++) {
											Node tempNode11 = tempNode1.getChildNodes().item(count11);
											if (tempNode11.getNodeType() == Node.ELEMENT_NODE) {
												if (tempNode11.getNodeName().equals("factory")) {
													if (tempNode11.hasAttributes()) {
														NamedNodeMap nodeMap = tempNode11.getAttributes();
														for (int i = 0; i < nodeMap.getLength(); i++) {
															Node node = nodeMap.item(i);
															if (node.getNodeName().equals("class")) {
																String[] args = node.getNodeValue().split("\\.");
																return args[args.length - 1];
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return "";
}
 
Example 15
Project: Artificial-Intelligent-chat-bot-   File: AIMLProcessor.java   Source Code and License Vote up 4 votes
/**
 * convert an AIML file to a list of categories.
 *
 * @param directory     directory containing the AIML file.
 * @param aimlFile      AIML file name.
 * @return              list of categories.
 */
public static ArrayList<Category> AIMLToCategories (String directory, String aimlFile) {
    try {
        ArrayList categories = new ArrayList<Category>();
        Node root = DomUtils.parseFile(directory+"/"+aimlFile);      // <aiml> tag
        String language = MagicStrings.default_language;
        if (root.hasAttributes()) {
            NamedNodeMap XMLAttributes = root.getAttributes();
            for(int i=0; i < XMLAttributes.getLength(); i++)
            {
                if (XMLAttributes.item(i).getNodeName().equals("language")) language = XMLAttributes.item(i).getNodeValue();
            }
        }
        NodeList nodelist = root.getChildNodes();
        for (int i = 0; i < nodelist.getLength(); i++)   {
            Node n = nodelist.item(i);
            //System.out.println("AIML child: " +n.getNodeName());
            if (n.getNodeName().equals("category")) {
                categoryProcessor(n, categories, "*", aimlFile, language);
            }
            else if (n.getNodeName().equals("topic")) {
                String topic = n.getAttributes().getNamedItem("name").getTextContent();
	//System.out.println("topic: " + topic);
                NodeList children = n.getChildNodes();
                for (int j = 0; j < children.getLength(); j++) {
                    Node m = children.item(j);
                    //System.out.println("Topic child: " + m.getNodeName());
                    if (m.getNodeName().equals("category")) {
                        categoryProcessor(m, categories, topic, aimlFile, language);
                    }
                }
            }
        }
        return categories;
    }
    catch (Exception ex) {
        System.out.println("AIMLToCategories: "+ex);
        ex.printStackTrace();
        return null;
    }
}
 
Example 16
Project: convertigo-engine   File: TwsDomTreeWrap.java   Source Code and License Vote up 4 votes
private void addNodeInTree(Node node, Document document, Element parent) {
    Element currentElement = createElement(document, node);
    currentElement.setAttribute("type", Short.toString(node.getNodeType()));

    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            currentElement.setAttribute("text", node.getNodeName());
            NamedNodeMap map = node.getAttributes();
            if (node.hasAttributes()) {
                Element attributes = createElement(document, node, false);
                attributes.setAttribute("text", "Attributes");
                attributes.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
                currentElement.appendChild(attributes);

                for (int i = 0; i < map.getLength(); ++i) {
                    Element attribute = createElement(document, map.item(i));
                    attribute.setAttribute("text", map.item(i).getNodeName() + "=\"" + map.item(i).getNodeValue() + "\"");
                    attribute.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
                    attributes.appendChild(attribute);
                }
            }
            break;

        case Node.TEXT_NODE:
            currentElement.setAttribute("text", node.getNodeValue() == null ? "" : node.getNodeValue().trim());
            break;

        case Node.ENTITY_NODE:
            currentElement.setAttribute("text", "[Entity]");
            break;

        case Node.ENTITY_REFERENCE_NODE:
            currentElement.setAttribute("text", "[Entityref]");
            break;

        case Node.PROCESSING_INSTRUCTION_NODE:
            currentElement.setAttribute("text", "[Pi]");
            break;

        case Node.COMMENT_NODE:
            currentElement.setAttribute("text", "[Comment]");
            break;

        case Node.DOCUMENT_FRAGMENT_NODE:
            currentElement.setAttribute("text", "[Docfgmt]");
            break;

        case Node.DOCUMENT_TYPE_NODE:
            currentElement.setAttribute("text", "[Doctype]");
            break;

        case Node.NOTATION_NODE:
            currentElement.setAttribute("text", "[Notation]");
            break;

        default:
            break;
    }
    parent.appendChild(currentElement);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node currentNode = nodeList.item(i);
        addNodeInTree(currentNode, document, currentElement);
    }
}
 
Example 17
Project: convertigo-engine   File: TwsDomTreeWrap.java   Source Code and License Vote up 4 votes
private static void addNodeInTree2(Node node, Document document, Element parent, int [] index) {
    Element currentElement = createElement2(document, node, index);
    currentElement.setAttribute("type", Short.toString(node.getNodeType()));

    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            currentElement.setAttribute("text", node.getNodeName());
            NamedNodeMap map = node.getAttributes();
            if (node.hasAttributes()) {
                Element attributes = createElement2(document, node, index);
                attributes.setAttribute("text", "Attributes");
                attributes.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
                currentElement.appendChild(attributes);

                for (int i = 0; i < map.getLength(); ++i) {
                    Element attribute = createElement2(document, map.item(i), index);
                    attribute.setAttribute("text", map.item(i).getNodeName() + "=\"" + map.item(i).getNodeValue() + "\"");
                    attribute.setAttribute("type", Short.toString(Node.ATTRIBUTE_NODE));
                    attributes.appendChild(attribute);
                }
            }
            break;

        case Node.TEXT_NODE:
            currentElement.setAttribute("text", node.getNodeValue() == null ? "" : node.getNodeValue().trim());
            break;

        case Node.ENTITY_NODE:
            currentElement.setAttribute("text", "[Entity]");
            break;

        case Node.ENTITY_REFERENCE_NODE:
            currentElement.setAttribute("text", "[Entityref]");
            break;

        case Node.PROCESSING_INSTRUCTION_NODE:
            currentElement.setAttribute("text", "[Pi]");
            break;

        case Node.COMMENT_NODE:
            currentElement.setAttribute("text", "[Comment]");
            break;

        case Node.DOCUMENT_FRAGMENT_NODE:
            currentElement.setAttribute("text", "[Docfgmt]");
            break;

        case Node.DOCUMENT_TYPE_NODE:
            currentElement.setAttribute("text", "[Doctype]");
            break;

        case Node.NOTATION_NODE:
            currentElement.setAttribute("text", "[Notation]");
            break;

        default:
            break;
    }
    parent.appendChild(currentElement);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node currentNode = nodeList.item(i);
        addNodeInTree2(currentNode, document, currentElement, index);
    }
}
 
Example 18
Project: OCCI-Studio   File: RegenerateConnectorAction.java   Source Code and License Vote up 4 votes
private String getExtensionScheme(IFile pluginXML) {
	try {
		IPath location = pluginXML.getLocation();
		if (location != null) {
			File file = location.toFile();

			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			Document doc = dBuilder.parse(file);

			if (doc.hasChildNodes()) {
				NodeList nodeList = doc.getChildNodes();
				for (int count = 0; count < nodeList.getLength(); count++) {
					Node tempNode = nodeList.item(count);
					if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
						if (tempNode.getNodeName().equals("plugin")) {
							for (int count1 = 0; count1 < tempNode.getChildNodes().getLength(); count1++) {
								Node tempNode1 = tempNode.getChildNodes().item(count1);
								if (tempNode1.getNodeType() == Node.ELEMENT_NODE) {
									if (tempNode1.getNodeName().equals("extension")) {
										for (int count11 = 0; count11 < tempNode1.getChildNodes()
												.getLength(); count11++) {
											Node tempNode11 = tempNode1.getChildNodes().item(count11);
											if (tempNode11.getNodeType() == Node.ELEMENT_NODE) {
												if (tempNode11.getNodeName().equals("factory")) {
													if (tempNode11.hasAttributes()) {
														NamedNodeMap nodeMap = tempNode11.getAttributes();
														for (int i = 0; i < nodeMap.getLength(); i++) {
															Node node = nodeMap.item(i);
															if (node.getNodeName().equals("uri")) {
																return node.getNodeValue()
																		.substring(0,
																				node.getNodeValue().length()
																						- ("/ecore".length()))
																		.concat("#");
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return "";
}
 
Example 19
Project: OCCI-Studio   File: RegenerateConnectorAction.java   Source Code and License Vote up 4 votes
private String getExtensionMetamodelURI(IFile pluginXML) {
	try {
		IPath location = pluginXML.getLocation();
		if (location != null) {
			File file = location.toFile();

			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			Document doc = dBuilder.parse(file);

			if (doc.hasChildNodes()) {
				NodeList nodeList = doc.getChildNodes();
				for (int count = 0; count < nodeList.getLength(); count++) {
					Node tempNode = nodeList.item(count);
					if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
						if (tempNode.getNodeName().equals("plugin")) {
							for (int count1 = 0; count1 < tempNode.getChildNodes().getLength(); count1++) {
								Node tempNode1 = tempNode.getChildNodes().item(count1);
								if (tempNode1.getNodeType() == Node.ELEMENT_NODE) {
									if (tempNode1.getNodeName().equals("extension")) {
										for (int count11 = 0; count11 < tempNode1.getChildNodes()
												.getLength(); count11++) {
											Node tempNode11 = tempNode1.getChildNodes().item(count11);
											if (tempNode11.getNodeType() == Node.ELEMENT_NODE) {
												if (tempNode11.getNodeName().equals("factory")) {
													if (tempNode11.hasAttributes()) {
														NamedNodeMap nodeMap = tempNode11.getAttributes();
														for (int i = 0; i < nodeMap.getLength(); i++) {
															Node node = nodeMap.item(i);
															if (node.getNodeName().equals("uri")) {
																return node.getNodeValue();
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return "";
}
 
Example 20
Project: OCCI-Studio   File: RegenerateConnectorAction.java   Source Code and License Vote up 2 votes
private static void printNote(NodeList nodeList) {

		for (int count = 0; count < nodeList.getLength(); count++) {

			Node tempNode = nodeList.item(count);

			// make sure it's element node.
			if (tempNode.getNodeType() == Node.ELEMENT_NODE) {

				// get node name and value
				System.out.println("\nNode Name =" + tempNode.getNodeName() + " [OPEN]");
				System.out.println("Node Value =" + tempNode.getTextContent());

				if (tempNode.hasAttributes()) {

					// get attributes names and values
					NamedNodeMap nodeMap = tempNode.getAttributes();

					for (int i = 0; i < nodeMap.getLength(); i++) {

						Node node = nodeMap.item(i);
						System.out.println("attr name : " + node.getNodeName());
						System.out.println("attr value : " + node.getNodeValue());

					}

				}

				if (tempNode.hasChildNodes()) {

					// loop again if has child nodes
					printNote(tempNode.getChildNodes());

				}

				System.out.println("Node Name =" + tempNode.getNodeName() + " [CLOSE]");

			}

		}

	}