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


Java XmlObject.newCursor方法代码示例

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


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

示例1: createSample

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
public String createSample( SchemaType sType )
{
	XmlObject object = XmlObject.Factory.newInstance();
	XmlCursor cursor = object.newCursor();
	// Skip the document node
	cursor.toNextToken();
	// Using the type and the cursor, call the utility method to get a
	// sample XML payload for that Schema element
	createSampleForType( sType, cursor );
	// Cursor now contains the sample payload
	// Pretty print the result. Note that the cursor is positioned at the
	// end of the doc so we use the original xml object that the cursor was
	// created upon to do the xmlText() against.

	cursor.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 = object.xmlText( options );

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

示例2: createSampleForElement

import org.apache.xmlbeans.XmlObject; //导入方法依赖的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

示例3: escapeAttributeValue

import org.apache.xmlbeans.XmlObject; //导入方法依赖的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

示例4: createSampleForType

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
public static String createSampleForType( SchemaType sType )
{
	XmlObject object = XmlObject.Factory.newInstance();
	XmlCursor cursor = object.newCursor();
	// Skip the document node
	cursor.toNextToken();
	// Using the type and the cursor, call the utility method to get a
	// sample XML payload for that Schema element
	new SampleXmlUtil( false ).createSampleForType( sType, cursor );
	// Cursor now contains the sample payload
	// Pretty print the result. Note that the cursor is positioned at the
	// end of the doc so we use the original xml object that the cursor was
	// created upon to do the xmlText() against.

	cursor.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 = object.xmlText( options );

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

示例5: createTextElement

import org.apache.xmlbeans.XmlObject; //导入方法依赖的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

示例6: createFromXmlObject

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
static XML createFromXmlObject(XMLLibImpl lib, XmlObject xo)
{
    XScriptAnnotation anno;
    XmlCursor curs = xo.newCursor();
    if (curs.currentTokenType().isStartdoc())
    {
        curs.toFirstContentToken();
    }
    try {
        anno = new XScriptAnnotation(curs);
        curs.setBookmark(anno);
    } finally {
        curs.dispose();
    }
    return new XML(lib, anno);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:17,代码来源:XML.java

示例7: escapeTextValue

import org.apache.xmlbeans.XmlObject; //导入方法依赖的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

示例8: addSection

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
public XmlObjectBuilder addSection(String sectionName, XmlObject section){
    cursor.beginElement(sectionName);
    cursor.push();
    XmlCursor srcCursor = section.newCursor();
    srcCursor.toNextToken();
    while(srcCursor.currentTokenType() != XmlCursor.TokenType.NONE && srcCursor.currentTokenType() !=  XmlCursor.TokenType.ENDDOC){
        srcCursor.copyXml(cursor);
        if(srcCursor.currentTokenType() == XmlCursor.TokenType.START) srcCursor.toEndToken();
        srcCursor.toNextToken();

    }
    cursor.pop();
    cursor.toEndToken();
    cursor.toNextToken();
    srcCursor.dispose();

    return this;
}
 
开发者ID:SmartBear,项目名称:ready-mqtt-plugin,代码行数:19,代码来源:XmlObjectBuilder.java

示例9: addSection

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
public XmlObjectBuilder addSection(String sectionName, XmlObject section) {
    cursor.beginElement(sectionName);
    cursor.push();
    XmlCursor srcCursor = section.newCursor();
    srcCursor.toNextToken();
    while (srcCursor.currentTokenType() != XmlCursor.TokenType.NONE
            && srcCursor.currentTokenType() != XmlCursor.TokenType.ENDDOC) {
        srcCursor.copyXml(cursor);
        if (srcCursor.currentTokenType() == XmlCursor.TokenType.START)
            srcCursor.toEndToken();
        srcCursor.toNextToken();

    }
    cursor.pop();
    cursor.toEndToken();
    cursor.toNextToken();
    srcCursor.dispose();

    return this;
}
 
开发者ID:hschott,项目名称:ready-websocket-plugin,代码行数:21,代码来源:XmlObjectBuilder.java

示例10: qualifySubstitutionGroup

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
  * Qualifies a valid member of a substitution group. This method tries to use the
  * built-in {@link XmlObject#substitute(QName, SchemaType)} and if succesful returns
  * a valid substitution which is usable (not disconnected). If it fails, it uses
  * low-level {@link XmlCursor} manipulation to qualify the substitution group. Note
  * that if the latter is the case the resulting document is disconnected and should
  * no longer be manipulated. Thus, use it as a final step after all markup is included.
  *
  * If newType is null, this method will skip {@link XmlObject#substitute(QName, SchemaType)}
  * and directly use {@link XmlCursor}. This can be used, if you are sure that the substitute
  * is not in the list of (pre-compiled) valid substitutions (this is the case if a schema
  * uses another schema's type as a base for elements. E.g. om:Observation uses gml:_Feature
  * as the base type).
  *
  * @param xobj
  * 		the abstract element
  * @param newInstance
  * 		the new {@link QName} of the instance
  * @param newType the new schemaType. if null, cursors will be used and the resulting object
  * 		will be disconnected.
  * @return if successful applied {@link XmlObject#substitute(QName, SchemaType)} a living object with a
  * 		type == newType is returned. Otherwise null is returned as you can no longer manipulate the object.
  */
 public static XmlObject qualifySubstitutionGroup(XmlObject xobj, QName newInstance, SchemaType newType) {
   XmlObject	substitute = null;

   if (newType != null) {
     substitute = xobj.substitute(newInstance, newType);
     if (substitute != null && substitute.schemaType() == newType
  && substitute.getDomNode().getLocalName().equals(newInstance.getLocalPart()))
     {
return substitute;
     }
   }

   XmlCursor cursor = xobj.newCursor();
   cursor.setName(newInstance);
   QName qName = new QName("http://www.w3.org/2001/XMLSchema-instance", "type");
   cursor.removeAttribute(qName);
   cursor.toNextToken();
   if (cursor.isNamespace()) {
     cursor.removeXml();
   }

   cursor.dispose();

   return null;
 }
 
开发者ID:pinaraf,项目名称:ebics,代码行数:49,代码来源:EbicsXmlFactory.java

示例11: createEmptyXML

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
static XML createEmptyXML(XMLLibImpl lib)
{
    XScriptAnnotation anno;

    XmlObject xo = XmlObject.Factory.newInstance();
    XmlCursor curs = xo.newCursor();
    try {
        anno = new XScriptAnnotation(curs);
        curs.setBookmark(anno);
    } finally {
        curs.dispose();
    }

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

示例12: removeToken

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
 *
 * @param curs
 */
protected void removeToken (XmlCursor curs)
{
    XmlObject xo = XmlObject.Factory.newInstance();

    // Don't delete anything move to another document so it gets orphaned nicely.
    XmlCursor tmpCurs = xo.newCursor();
    tmpCurs.toFirstContentToken();


    curs.moveXml(tmpCurs);

    tmpCurs.dispose();
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:18,代码来源:XML.java

示例13: copy

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
 *
 * @param cursToCopy
 * @return
 */
private XmlCursor copy (XmlCursor cursToCopy)
{
    XmlObject xo = XmlObject.Factory.newInstance();

    XmlCursor copyCurs = null;

    if (cursToCopy.currentTokenType().isText())
    {
        try
        {
            // Try just as a textnode, to do that we need to wrap the text in a special fragment tag
            // that is not visible from the XmlCursor.
            copyCurs = XmlObject.Factory.parse("<x:fragment xmlns:x=\"http://www.openuri.org/fragment\">" +
                                       cursToCopy.getChars() +
                                       "</x:fragment>").newCursor();
            if (!cursToCopy.toNextSibling())
            {
                if (cursToCopy.currentTokenType().isText())
                {
                    cursToCopy.toNextToken();   // It's not an element it's text so skip it.
                }
            }
        }
        catch (Exception ex)
        {
            throw ScriptRuntime.typeError(ex.getMessage());
        }
    }
    else
    {
        copyCurs = xo.newCursor();
        copyCurs.toFirstContentToken();
        if (cursToCopy.currentTokenType() == XmlCursor.TokenType.STARTDOC)
        {
            cursToCopy.toNextToken();
        }
        
        cursToCopy.copyXml(copyCurs);
        if (!cursToCopy.toNextSibling())        // If element skip element.
        {
            if (cursToCopy.currentTokenType().isText())
            {
                cursToCopy.toNextToken();       // It's not an element it's text so skip it.
            }
        }

    }

    copyCurs.toStartDoc();
    copyCurs.toFirstContentToken();

    return copyCurs;
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:59,代码来源:XML.java

示例14: insertChild

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
 *
 * @param curs
 * @param xmlToInsert
 */
private void insertChild(XmlCursor curs, Object xmlToInsert)
{
    if (xmlToInsert == null || xmlToInsert instanceof Undefined)
    {
        // Do nothing
    }
    else if (xmlToInsert instanceof XmlCursor)
    {
        moveSrcToDest((XmlCursor)xmlToInsert, curs, true);
    }
    else if (xmlToInsert instanceof XML)
    {
        XML xmlValue = (XML) xmlToInsert;

        // If it's an attribute, then change to text node
        if (xmlValue.tokenType() == XmlCursor.TokenType.ATTR)
        {
            insertChild(curs, xmlValue.toString());
        }
        else
        {
            XmlCursor cursToInsert = ((XML) xmlToInsert).newCursor();

            moveSrcToDest(cursToInsert, curs, true);

            cursToInsert.dispose();
        }
    }
    else if (xmlToInsert instanceof XMLList)
    {
        XMLList list = (XMLList) xmlToInsert;

        for (int i = 0; i < list.length(); i++)
        {
            insertChild(curs, list.item(i));
        }
    }
    else
    {
        // Convert to string and make XML out of it
        String  xmlStr = ScriptRuntime.toString(xmlToInsert);
        XmlObject xo = XmlObject.Factory.newInstance();         // Create an empty document.

        XmlCursor sourceCurs = xo.newCursor();
        sourceCurs.toNextToken();

        // To hold the text.
        sourceCurs.insertChars(xmlStr);

        sourceCurs.toPrevToken();

        // Call us again with the cursor.
        moveSrcToDest(sourceCurs, curs, true);
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:61,代码来源:XML.java

示例15: evaluate

import org.apache.xmlbeans.XmlObject; //导入方法依赖的package包/类
/**
     * Using XPath or XQuery.
     * NOTE!!!! To use this code, need to include
     * xbean_xpath.jar, saxon9.jar, saxon9-dom.jar in CLASSPATH
     * in startWebLogic.cmd
     * @param xmlbean
     * @param path
     * @return
     */

    public static String evaluate(XmlObject xmlbean, String path) {
        XmlCursor cursor = xmlbean.newCursor();
        String value;
        
// 1.2.3. use XQuery or selectPath
//
//        cursor.toFirstChild();
//        String defaultNamespace = cursor.namespaceForPrefix("");
//        String namespaceDecl = "declare default element namespace '" + defaultNamespace + "';";
//        Map<String,String> namespaces = new HashMap<String,String>();
//        cursor.getAllNamespaces(namespaces);
//        for (String prefix : namespaces.keySet())
//        {
//            namespaceDecl += "declare namespace " + prefix + "='" + namespaces.get(prefix) + "';";
//        }
//  1. use XQuery
//        XmlCursor results = cursor.execQuery(namespaceDecl + path);
//        value = (results==null)?null:results.getTextValue();
        
//  2. use selectPath on XmlObject
//        XmlObject[] result = xmlbean.selectPath(namespaceDecl + path);
        
//  3. use selectPath on XmlCursor   
//        cursor.toParent();
//        XmlOptions options = new XmlOptions();
//        options.put(Path.PATH_DELEGATE_INTERFACE,"org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath");
//        cursor.selectPath(namespaceDecl + path, options);
//        if (cursor.getSelectionCount()>0) {
//            cursor.toNextSelection();
//            value = cursor.getTextValue();
//        } else value = null;

// 4. use our own implementation
        try {
            XmlPath matcher = new XmlPath(path);
            value = matcher.evaluate_segment(cursor, matcher.path_seg);
        } catch (XmlException e) {
            value = null; // xpath syntax error - treated as no match
        }
        
        cursor.dispose();
        return value;
    }
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:54,代码来源:XmlPath.java


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