当前位置: 首页>>代码示例>>Java>>正文


Java XmlCursor.beginElement方法代码示例

本文整理汇总了Java中org.apache.xmlbeans.XmlCursor.beginElement方法的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor.beginElement方法的具体用法?Java XmlCursor.beginElement怎么用?Java XmlCursor.beginElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.xmlbeans.XmlCursor的用法示例。


在下文中一共展示了XmlCursor.beginElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSampleForElement

import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
public static String createSampleForElement( SchemaGlobalElement element )
{
	XmlObject xml = XmlObject.Factory.newInstance();

	XmlCursor c = xml.newCursor();
	c.toNextToken();
	c.beginElement( element.getName() );

	new SampleXmlUtil( false ).createSampleForType( element.getType(), c );

	c.dispose();

	XmlOptions options = new XmlOptions();
	options.put( XmlOptions.SAVE_PRETTY_PRINT );
	options.put( XmlOptions.SAVE_PRETTY_PRINT_INDENT, 3 );
	options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
	options.setSaveOuter();
	String result = xml.xmlText( options );

	return result;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:22,代码来源:SampleXmlUtil.java

示例2: escapeAttributeValue

import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
 * Escapes the reserved characters in a value of an attribute
 *
 * @param value Unescaped text
 * @return The escaped text
 */
public String escapeAttributeValue(Object value)
{
    String text = ScriptRuntime.toString(value);

    if (text.length() == 0) return "";

    XmlObject xo = XmlObject.Factory.newInstance();

    XmlCursor cursor = xo.newCursor();
    cursor.toNextToken();
    cursor.beginElement("a");
    cursor.insertAttributeWithValue("a", text);
    cursor.dispose();

    String elementText = xo.toString();
    int begin = elementText.indexOf('"');
    int end = elementText.lastIndexOf('"');
    return elementText.substring(begin + 1, end);
}
 
开发者ID:CyboticCatfish,项目名称:code404,代码行数:26,代码来源:XMLLibImpl.java

示例3: createTextElement

import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
 *
 * @param qname
 * @param value
 * @return
 */
static XML createTextElement(XMLLibImpl lib, javax.xml.namespace.QName qname, String value)
{
    XScriptAnnotation anno;

    XmlObject xo = XmlObject.Factory.newInstance();
    XmlCursor cursor = xo.newCursor();
    try {
        cursor.toNextToken();

        cursor.beginElement(qname.getLocalPart(), qname.getNamespaceURI());
        //if(namespace.length() > 0)
        //    cursor.insertNamespace("", namespace);
        cursor.insertChars(value);

        cursor.toStartDoc();
        cursor.toNextToken();
        anno = new XScriptAnnotation(cursor);
        cursor.setBookmark(anno);
    } finally {
        cursor.dispose();
    }

    return new XML(lib, anno);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:31,代码来源:XML.java

示例4: escapeTextValue

import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
 * Escapes the reserved characters in a value of a text node
 *
 * @param value Unescaped text
 * @return The escaped text
 */
public String escapeTextValue(Object value)
{
    if (value instanceof XMLObjectImpl) {
        return ((XMLObjectImpl)value).toXMLString(0);
    }

    String text = ScriptRuntime.toString(value);

    if (text.length() == 0) return text;

    XmlObject xo = XmlObject.Factory.newInstance();

    XmlCursor cursor = xo.newCursor();
    cursor.toNextToken();
    cursor.beginElement("a");
    cursor.insertChars(text);
    cursor.dispose();

    String elementText = xo.toString();
    int begin = elementText.indexOf('>') + 1;
    int end = elementText.lastIndexOf('<');
    return (begin < end) ? elementText.substring(begin, end) : "";
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:30,代码来源:XMLLibImpl.java

示例5: insertNewTable

import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
	 * 在某个段落起始处插入表格
	 * 
	 * @param run
	 * @param row
	 * @param col
	 * @return
	 */
	public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
		XmlCursor cursor = ((XWPFParagraph)run.getParent()).getCTP().newCursor();

		// XmlCursor cursor = run.getCTR().newCursor();
		if (isCursorInBody(cursor)) {
			String uri = CTTbl.type.getName().getNamespaceURI();
			String localPart = "tbl";
			cursor.beginElement(localPart, uri);
			cursor.toParent();

			CTTbl t = (CTTbl) cursor.getObject();
			XWPFTable newT = new XWPFTable(t, this, row, col);
			XmlObject o = null;
			while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
				o = cursor.getObject();
			}
			if (!(o instanceof CTTbl)) {
				tables.add(0, newT);
			} else {
				int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
				tables.add(pos, newT);
			}
			int i = 0;
			XmlCursor tableCursor = t.newCursor();
			try {
				cursor.toCursor(tableCursor);
				while (cursor.toPrevSibling()) {
					o = cursor.getObject();
					if (o instanceof CTP || o instanceof CTTbl){
						i++;
					}
				}
				bodyElements.add(i > bodyElements.size() ? bodyElements.size() : i, newT);
//				bodyElements.add(i, newT);
				cursor.toCursor(tableCursor);
				cursor.toEndToken();
				return newT;
			} finally {
				tableCursor.dispose();
			}
		}
		return null;
	}
 
开发者ID:Sayi,项目名称:poi-tl,代码行数:52,代码来源:NiceXWPFDocument.java

示例6: insertNewParagraph

import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
	 * 在某个段落起始处插入段落
	 * @param run
	 * @return
	 */
	public XWPFParagraph insertNewParagraph(XWPFRun run) {
//		XmlCursor cursor = run.getCTR().newCursor();
		XmlCursor cursor = ((XWPFParagraph)run.getParent()).getCTP().newCursor();
		if (isCursorInBody(cursor)) {
            String uri = CTP.type.getName().getNamespaceURI();
            /*
             * TODO DO not use a coded constant, find the constant in the OOXML
             * classes instead, as the child of type CT_Paragraph is defined in the 
             * OOXML schema as 'p'
             */
            String localPart = "p";
            // creates a new Paragraph, cursor is positioned inside the new
            // element
            cursor.beginElement(localPart, uri);
            // move the cursor to the START token to the paragraph just created
            cursor.toParent();
            CTP p = (CTP) cursor.getObject();
            XWPFParagraph newP = new XWPFParagraph(p, this);
            XmlObject o = null;
            /*
             * move the cursor to the previous element until a) the next
             * paragraph is found or b) all elements have been passed
             */
            while (!(o instanceof CTP) && (cursor.toPrevSibling())) {
                o = cursor.getObject();
            }
            /*
             * if the object that has been found is a) not a paragraph or b) is
             * the paragraph that has just been inserted, as the cursor in the
             * while loop above was not moved as there were no other siblings,
             * then the paragraph that was just inserted is the first paragraph
             * in the body. Otherwise, take the previous paragraph and calculate
             * the new index for the new paragraph.
             */
            if ((!(o instanceof CTP)) || (CTP) o == p) {
                paragraphs.add(0, newP);
            } else {
                int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1;
                paragraphs.add(pos, newP);
            }

            /*
             * create a new cursor, that points to the START token of the just
             * inserted paragraph
             */
            XmlCursor newParaPos = p.newCursor();
            try {
                /*
                 * Calculate the paragraphs index in the list of all body
                 * elements
                 */
                int i = 0;
                cursor.toCursor(newParaPos);
                while (cursor.toPrevSibling()) {
                    o = cursor.getObject();
                    if (o instanceof CTP || o instanceof CTTbl)
                        i++;
                }
                bodyElements.add(i, newP);
                cursor.toCursor(newParaPos);
                cursor.toEndToken();
                return newP;
            } finally {
                newParaPos.dispose();
            }
        }
        return null;
	}
 
开发者ID:Sayi,项目名称:poi-tl,代码行数:74,代码来源:NiceXWPFDocument.java


注:本文中的org.apache.xmlbeans.XmlCursor.beginElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。