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


Java Element.getParent方法代碼示例

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


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

示例1: insertHtmlComment

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  Insert an HTML comment into the html source.
 *
 * @param  e  NOT YET DOCUMENTED
 * @param  s  NOT YET DOCUMENTED
 */
protected void insertHtmlComment(Element e, String s) {
	prtln("\ninsertHtmlComment()");
	Element comment = df.createElement("st__htmlComment");
	comment.setText(s);
	Element parent = e.getParent();

	if (parent != null) {
		List children = parent.elements();
		int index = children.indexOf(e);
		children.add(index, comment);
	}
	else {
		// prtlnErr("PARENT NOT FOUND");
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:22,代碼來源:MdeNode.java

示例2: processExtension

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  Process an exention element of a DerivedContent model. For extensions (used
 *  in Simple and ComplexContent type definitions, we create a dummy element of
 *  the extension's base type. The dummy element has an attribute of
 *  "extension" so it can be identified and handled properly when it is fed
 *  back into processSchemaElement and expanded as if it were an element of the
 *  baseType.<p>
 *
 *  Finaly the attributes (if any) are processed as if they were defined in the
 *  parent of the parent element, which is the enclosing ComplexType.
 *
 * @param  e              The schema extention element being processed
 * @param  parent         The instanceDoc parent of the extention (a simple or
 *      complexContent element)
 * @exception  Exception  NOT YET DOCUMENTED
 */
private void processExtension(Element e, Element parent) throws Exception {

	String baseType = e.attributeValue("base");
	String parentName = XPathUtils.getNodeName(getPath(parent));

	prtln("\n processExtension() handling extension (baseType: " + baseType + ")", 1);
	prtln(pp(e));

	// create dummy element
	//  embed namespace information into the dummy element so it is available to "isBuiltInType"
	QName qname = df.createQName("element", e.getNamespace());
	Element extElement = df.createElement(qname);

	extElement.addAttribute("type", baseType);
	extElement.addAttribute("extension", "true");
	extElement.addAttribute("name", parentName);

	prtln("\t ... extn element: " + extElement.asXML() + "\n", 1);

	/*
	 *  // print out some DEBUGGING info
	 *  if (parentName.equals("catalog")) {
	 *  prtln("parent name = " + parentName, 1);
	 *  prtln("base = " + baseType, 1);
	 *  prtln("dummy extension element: " + extElement.asXML(), 1);
	 *  }
	 */
	// this (or something like it must be here to catch the extension attributes?
	processSchemaElement(extElement, parent);

	// take care of the attributes of this extention
	for (Iterator i = e.elementIterator(); i.hasNext(); ) {
		Element grandParent = parent.getParent();
		Element childAttribute = (Element) i.next();
		processSchemaElement(childAttribute, parent);
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:54,代碼來源:StructureWalker.java

示例3: getHistoryElement

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  Gets the historyElement attribute of the DcsDataRecord object
 *
 * @param  changeDate  NOT YET DOCUMENTED
 * @return             The historyElement value
 */
private Element getHistoryElement(String changeDate) {
	List dateElements = doc.selectNodes("//dcsDataRecord/statusEntries/statusEntry/changeDate");
	if (dateElements != null && dateElements.size() > 0)
		for (Iterator i = dateElements.iterator(); i.hasNext(); ) {
			Element dateElement = (Element) i.next();
			if (dateElement.getText().equals(changeDate))
				return dateElement.getParent();
		}
	return null;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:17,代碼來源:DcsDataRecord.java

示例4: replace

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 * Replace a XML element.
 *
 * @param xpath XPath , pointing to a XML element
 * @param object the new XML element
 * @return this instance
 * @throws XMLException
 */
@PublicAtsApi
public XmlText replace(
                        String xpath,
                        Object object ) throws XMLException {

    if (StringUtils.isNullOrEmpty(xpath)) {
        throw new XMLException("Null/empty xpath is not allowed.");
    }

    if (object == null) {
        throw new XMLException("Null object is not allowed for replacement."
                               + "If you want to remove existing XML element, use XMLText.remove().");
    }

    Element newElement = null;

    if (object instanceof XmlText) {
        newElement = ((XmlText) object).root;
    }

    if (object instanceof String) {
        if (StringUtils.isNullOrEmpty((String) object)) {

            throw new XMLException("Null/empty String object is not allowed for replacement."
                                   + "If you want to remove existing XML element, use XMLText.remove().");

        }
        newElement = new XmlText((String) object).root;
    }

    if (newElement == null) {
        throw new XMLException("Given object for replacing an existing one is from invallid class instance. "
                               + "Use String or XMLText instances only.");
    }

    Element oldElement = findElement(xpath);

    if (oldElement != null) {

        if (oldElement.isRootElement()) {
            throw new XMLException("You cannot replace the root element of the XML document.");
        }

        Element parent = oldElement.getParent();
        if (parent != null) {
            parent.elements().set(parent.elements().indexOf(oldElement), newElement);
        } else {
            throw new XMLException("Parent for element with xpath '" + xpath + "' could not be found.");
        }

    } else {
        throw new XMLException("'" + xpath + "' is not a valid path");
    }

    return this;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:65,代碼來源:XmlText.java

示例5: getTypeDefs

import org.dom4j.Element; //導入方法依賴的package包/類
/**
	 *  Gets the typeDefs attribute of the SchemaReader object
	 *
	 * @param  typeSpec       NOT YET DOCUMENTED
	 * @exception  Exception  NOT YET DOCUMENTED
	 */
	private void getTypeDefs(String typeSpec) throws Exception {
		// prtln ("getTypeDefs: " + typeSpec + " (" + this.source.toString() + ")");
		if (doc == null) {
			return;
		}
		List list = doc.selectNodes("//" + NamespaceRegistry.makeQualifiedName (xsdPrefix, typeSpec));

		for (Iterator iter = list.iterator(); iter.hasNext(); ) {
			Element element = (Element) iter.next();
			String typeName = element.attributeValue("name");
			boolean isInlineTypeDef = false;
			
			// type definitions without a name attribute are inline definitions
			if (typeName == null) {
				Element parent = element.getParent();
				if (parent == null) {
					prtlnErr("WARNING: parent not found for in-line typeDef\n" + element.asXML());
					continue;
				}
				String parentName = parent.attributeValue("name");
				typeName = definitionMiner.getInlineTypeName(parentName);

				// handle union inlines differently than others
				if (isUnionDataType (parent))
					addMemberType (parent, typeName);
				else
					parent.addAttribute("type", typeName);
				
				// parent.addAttribute("type", typeName);
				element.addAttribute("name", typeName);
				isInlineTypeDef = true;
			}

			GenericType typeDef = null;
			try {
				if (typeSpec == "complexType") {
					typeDef = new ComplexType(element, source.toString(), targetNamespace, this);
					typeDef.setInline(isInlineTypeDef);
				}
				else if (typeSpec == "simpleType") {
					typeDef = new SimpleType(element, source.toString(), targetNamespace, this);
					typeDef.setInline(isInlineTypeDef);
				}
				else
					throw new Exception("unknown typeSpec: " + typeSpec);
	
				if (typeDef != null) {
					try {
						definitionMiner.addGlobalDef(typeName, typeDef, targetNamespace);
					} catch (Exception e) {
						prtlnErr(e.getMessage());
					}
				}
			} catch (Throwable t) {
				prtlnErr ("WARNING: not able to create typeDef for this element:" + Dom4jUtils.prettyPrint(element));
/* 				prtlnErr ("\tReason: " + t.getMessage());
				t.printStackTrace(); */
			}
		}
	}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:67,代碼來源:SchemaReader.java


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