当前位置: 首页>>代码示例>>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;未经允许,请勿转载。