本文整理匯總了Java中org.dom4j.Node.ELEMENT_NODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Node.ELEMENT_NODE屬性的具體用法?Java Node.ELEMENT_NODE怎麽用?Java Node.ELEMENT_NODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.dom4j.Node
的用法示例。
在下文中一共展示了Node.ELEMENT_NODE屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
@Override
public <T> T process(T xml, Iterable<Effect> effects) throws XmlBuilderException {
if (!canHandle(xml)) {
throw new IllegalArgumentException("XML model is not supported");
}
final Node xmlNode = (Node) xml;
final Dom4jNode<?> node;
switch (xmlNode.getNodeType()) {
case Node.DOCUMENT_NODE:
node = new Dom4jDocument((Document) xmlNode);
break;
case Node.ELEMENT_NODE:
node = new Dom4jElement((Element) xmlNode);
break;
case Node.ATTRIBUTE_NODE:
node = new Dom4jAttribute((Attribute) xmlNode);
break;
default:
throw new IllegalArgumentException("XML node type is not supported");
}
final Navigator<Dom4jNode> navigator = new Dom4jNavigator(xmlNode);
for (Effect effect : effects) {
effect.perform(navigator, node);
}
return xml;
}
示例2: hasChildren
/**
* Return true if the specified node is an Element and has either a
* sub-element, or an attribute (even if they are empty), OR content.
*
* @param xpath xpath to the node to be evaluated for children
* @return true if sub-elements, or attributes, false otherwise or if
* node is not an Element
*/
public boolean hasChildren(String xpath) {
// prtln ("\nhasChildren: " + xpath);
if (xpath == null || xpath.trim().length() == 0)
return false;
Node node = doc.selectSingleNode(xpath);
if (node == null) {
prtlnErr("\thasChildren() could not find node: (" + xpath + ")");
return false;
}
if (node.getNodeType() != Node.ELEMENT_NODE) {
prtlnErr("hasChildern() called with an non-Element - returning false");
return false;
}
Element e = (Element) node;
// we used to check for "hasText" but why would we want to do that here???
/*
We DO want to check in the case of an element that can contain text which ALSO
has attributes. So we can do this check IF the typeDef is the right kind ...
*/
boolean hasText = (e.getTextTrim() != null && e.getTextTrim().length() > 0);
if (hasText)
return true;
return (e.elements().size() > 0 ||
e.attributeCount() > 0);
}
示例3: isEmpty
/**
* Returns true if an element (recursively) has no textual content, no
* children, and no attributes with values.<p>
*
* Note: returns FALSE if no node exists at the given path.
*
* @param xpath Description of the Parameter
* @return true if empty, false if any errors are encountered
*/
public boolean isEmpty(String xpath) {
Node node = doc.selectSingleNode(xpath);
String msg = "";
// return FALSE if a node is not found (this is kind of a wierd convention?)
if (node == null) {
msg = " ... couldn't find node at " + xpath + " returning FALSE";
// prtlnErr(msg);
return false;
}
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
String content = node.getText();
// return (content == null || content.trim().length() == 0);
// 2/28/07 - no longer ignore whitespace!
return (content == null || content.length() == 0);
}
if (node.getNodeType() != Node.ELEMENT_NODE) {
msg = " ... called with an unknown type of node - returning false";
// prtlnErr(msg);
return false;
}
boolean ret = Dom4jUtils.isEmpty((Element) node);
return ret;
}
示例4: getNodeExistsWithRequiredAttribute
/**
* Return true if the node specified by key exists in the instance document
* and it has a required attribute in the instance document.
*
* @param key a jsp-encoded xpath
* @return The nodeExistsWithRequiredAttribute value
*/
public String getNodeExistsWithRequiredAttribute(String key) {
String xpath = XPathUtils.decodeXPath(key);
Node node = docMap.selectSingleNode(xpath);
if (node == null) {
return FALSE;
}
if (node.getNodeType() != Node.ELEMENT_NODE) {
return FALSE;
}
Element element = (Element) node;
if (element.attributes().isEmpty()) {
return FALSE;
}
/* check attributes for a required one */
for (Iterator i = element.attributeIterator(); i.hasNext(); ) {
Attribute attribute = (Attribute) i.next();
String attPath = xpath + "/@" + attribute.getQualifiedName();
SchemaNode schemaNode = this.schemaHelper.getSchemaNode(attPath);
if (schemaNode == null) {
// prtln ("schemaNode not found for attribute (" + attPath + ")");
continue;
}
if (schemaNode.isRequired())
return TRUE;
}
return FALSE;
}
示例5: prependCopy
@Override
public void prependCopy(Dom4jNode node) throws XmlBuilderException {
final Node wrappedNode = node.getNode();
if (Node.ELEMENT_NODE != wrappedNode.getNodeType()) {
throw new XmlBuilderException("Unable to copy non-element node " + node);
}
final Element parent = wrappedNode.getParent();
if (null == parent) {
throw new XmlBuilderException("Unable to prepend - no parent found of " + node);
}
final int prependIndex = parent.indexOf(wrappedNode);
final Element copiedNode = ((Element) wrappedNode).createCopy();
parent.elements().add(prependIndex, copiedNode);
}
示例6: init
/**
* Description of the Method
*
*@param e Description of the Parameter
*/
private void init(Element e) {
// prtln ("init with:\n" + e.asXML());
if (validatingType == null) {
// validatingType = typeDef;
validatingType = findValidatingType(getTypeDef());
}
setIsChoiceMember();
attMap = new HashMap();
propMap = new HashMap();
String nodeTypeString = e.getName();
if (nodeTypeString.equals("element") || nodeTypeString.equals ("any")) {
nodeType = Node.ELEMENT_NODE;
minOccurs = SchemaHelper.getMinOccurs(e);
maxOccurs = SchemaHelper.getMaxOccurs(e);
// prtln ("minOccurs: " + minOccurs + " maxOccurs: " + maxOccurs);
String nillable = e.attributeValue("nillable", SchemaHelper.NILLABLE_DEFAULT);
if ((nillable != null) && (nillable.trim().length() > 0)) {
attMap.put("nillable", nillable);
}
if (e.attributeValue("fixed", null) != null) {
readOnly = true;
}
attMap.put ("substitutionGroup", e.attributeValue("substitutionGroup", ""));
attMap.put ("abstract", e.attributeValue("abstract", ""));
}
else if (nodeTypeString.equals("attribute")) {
nodeType = Node.ATTRIBUTE_NODE;
String use = e.attributeValue("use");
if ((use != null) && (use.trim().length() > 0)) {
attMap.put("use", use);
}
}
else {
nodeType = Node.UNKNOWN_NODE;
}
if (schemaDocAware)
extractDocumentation (e);
// prtln ("Instantiated SchemaNode\n" + toString());
}
示例7: writeElement
protected void writeElement(Element element) throws IOException {
int size = element.nodeCount();
String qualifiedName = element.getQualifiedName();
writePrintln();
indent();
writer.write("<");
writer.write(qualifiedName);
boolean textOnly = true;
for (int i = 0; i < size; i++) {
Node node = element.node(i);
if (node instanceof Element) {
textOnly = false;
} else if (node instanceof Comment) {
textOnly = false;
}
}
writeAttributes(element);
lastOutputNodeType = Node.ELEMENT_NODE;
if (size <= 0) {
writeEmptyElementClose(qualifiedName);
} else {
writer.write(">");
if (textOnly) {
// we have at least one text node so lets assume
// that its non-empty
writeElementContent(element);
} else {
if (element.attributeCount() > 3)
writePrintln();
// we know it's not null or empty from above
++indentLevel;
writeElementContent(element);
--indentLevel;
writePrintln();
indent();
}
writer.write("</");
writer.write(qualifiedName);
writer.write(">");
}
if (element.attributeCount() > 2 && indentLevel > 0)
writePrintln();
lastOutputNodeType = Node.ELEMENT_NODE;
}
示例8: isElement
/**
* Gets the element attribute of the SchemaNode object
*
*@return The element value
*/
public boolean isElement() {
return (getNodeType() == Node.ELEMENT_NODE);
}