本文整理汇总了Java中org.apache.xmlbeans.XmlCursor类的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor类的具体用法?Java XmlCursor怎么用?Java XmlCursor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmlCursor类属于org.apache.xmlbeans包,在下文中一共展示了XmlCursor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSample
import org.apache.xmlbeans.XmlCursor; //导入依赖的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;
}
示例2: 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;
}
示例3: 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);
}
示例4: render
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
@Override
public void render(ElementTemplate eleTemplate, Object data,
XWPFTemplate template) {
NiceXWPFDocument doc = template.getXWPFDocument();
RunTemplate runTemplate = (RunTemplate) eleTemplate;
XWPFRun run = runTemplate.getRun();
try {
XmlCursor newCursor = ((XWPFParagraph)run.getParent()).getCTP().newCursor();
newCursor.toParent();
//if (newCursor.getObject() instanceof CTTc)
newCursor.toParent();
newCursor.toParent();
XmlObject object = newCursor.getObject();
XWPFTable table = doc.getTable((CTTbl) object);
render(table, data);
} catch (Exception e) {
logger.error("dynamic table error:" + e.getMessage(), e);
}
}
示例5: createSampleForType
import org.apache.xmlbeans.XmlCursor; //导入依赖的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;
}
示例6: 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);
}
示例7: createFromXmlObject
import org.apache.xmlbeans.XmlCursor; //导入依赖的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);
}
示例8: tokenType
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
/**
*
* @return
*/
XmlCursor.TokenType tokenType()
{
XmlCursor.TokenType result;
XmlCursor curs = newCursor();
if (curs.isStartdoc())
{
curs.toFirstContentToken();
}
result = curs.currentTokenType();
curs.dispose();
return result;
}
示例9: remove
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
/**
*
*/
void remove ()
{
XmlCursor childCurs = newCursor();
if (childCurs.currentTokenType().isStartdoc())
{
// Remove on the document removes all children.
TokenType tt = childCurs.toFirstContentToken();
while (!tt.isEnd() && !tt.isEnddoc())
{
removeToken(childCurs);
tt = childCurs.currentTokenType(); // Now see where we're pointing after the delete -- next token.
}
}
else
{
removeToken(childCurs);
}
childCurs.dispose();
}
示例10: appendChild
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
/**
*
* @param xml
* @return
*/
XML appendChild(Object xml)
{
XmlCursor curs = newCursor();
if (curs.isStartdoc())
{
curs.toFirstContentToken();
}
// Move the cursor to the end of this element
if (curs.isStart())
{
curs.toEndToken();
}
insertChild(curs, xml);
curs.dispose();
return this;
}
示例11: child
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
XMLList child(XMLName xmlName)
{
if (xmlName == null)
return new XMLList(lib);
XMLList result;
if (xmlName.localName().equals("*"))
{
result = allChildNodes(xmlName.uri());
}
else
{
result = matchChildren(XmlCursor.TokenType.START, xmlName);
}
return result;
}
示例12: copy
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
/**
*
* @return
*/
Object copy()
{
XmlCursor srcCurs = newCursor();
if (srcCurs.isStartdoc())
{
srcCurs.toFirstContentToken();
}
XML xml = createEmptyXML(lib);
XmlCursor destCurs = xml.newCursor();
destCurs.toFirstContentToken();
srcCurs.copyXml(destCurs);
destCurs.dispose();
srcCurs.dispose();
return xml;
}
示例13: hasSimpleContent
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
/**
*
* @return
*/
boolean hasSimpleContent()
{
boolean simpleContent = false;
XmlCursor curs = newCursor();
if (curs.isAttr() || curs.isText()) {
return true;
}
if (curs.isStartdoc())
{
curs.toFirstContentToken();
}
simpleContent = !(curs.toFirstChild());
curs.dispose();
return simpleContent;
}
示例14: localName
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
/**
*
* @return
*/
String localName()
{
XmlCursor cursor = newCursor();
if (cursor.isStartdoc())
cursor.toFirstContentToken();
String name = null;
if(cursor.isStart() ||
cursor.isAttr() ||
cursor.isProcinst())
{
javax.xml.namespace.QName qname = cursor.getName();
name = qname.getLocalPart();
}
cursor.dispose();
return name;
}
示例15: prependChild
import org.apache.xmlbeans.XmlCursor; //导入依赖的package包/类
/**
*
* @param xml
* @return
*/
XML prependChild (Object xml)
{
XmlCursor curs = newCursor();
if (curs.isStartdoc())
{
curs.toFirstContentToken();
}
// Move the cursor to the first content token
curs.toFirstContentToken();
insertChild(curs, xml);
curs.dispose();
return this;
}