本文整理匯總了Java中org.w3c.dom.Node.hasAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.hasAttributes方法的具體用法?Java Node.hasAttributes怎麽用?Java Node.hasAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.hasAttributes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: unevaluatedXML
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* 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;
}
示例3: toObject
import org.w3c.dom.Node; //導入方法依賴的package包/類
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;
}
}
示例4: traverse
import org.w3c.dom.Node; //導入方法依賴的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("/>");
}
}
示例5: 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);
}
}
}
示例6: extractQueryDefinition
import org.w3c.dom.Node; //導入方法依賴的package包/類
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);
}
}
}
示例7: unevaluatedXML
import org.w3c.dom.Node; //導入方法依賴的package包/類
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
}
示例8: updateAttributeValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
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));
}
}
}
}
示例9: hasAttributes
import org.w3c.dom.Node; //導入方法依賴的package包/類
public boolean hasAttributes(final String szPath)
{
ensureRoot();
Node oNode = getNodeHelper(szPath, false, false);
if( oNode == null )
{
return false;
}
return oNode.hasAttributes();
}
示例10: wantAlpha
import org.w3c.dom.Node; //導入方法依賴的package包/類
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;
}
示例11: getExtensionFactoryClass
import org.w3c.dom.Node; //導入方法依賴的package包/類
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 "";
}
示例12: AIMLToCategories
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* 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;
}
}
示例13: addNodeInTree
import org.w3c.dom.Node; //導入方法依賴的package包/類
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);
}
}
示例14: addNodeInTree2
import org.w3c.dom.Node; //導入方法依賴的package包/類
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);
}
}
示例15: getExtensionScheme
import org.w3c.dom.Node; //導入方法依賴的package包/類
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 "";
}