本文整理汇总了Java中org.apache.xmlbeans.XmlCursor.toNextToken方法的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor.toNextToken方法的具体用法?Java XmlCursor.toNextToken怎么用?Java XmlCursor.toNextToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xmlbeans.XmlCursor
的用法示例。
在下文中一共展示了XmlCursor.toNextToken方法的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: 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);
}
示例3: nextToken
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* filter out empty textNodes here
*
* @param xml
*/
private static void nextToken(XmlCursor xml)
{
do
{
xml.toNextToken();
if (!xml.isText())
{
// Not a text node
break;
}
else if (xml.getChars().trim().length() > 0)
{
// Text node is not empty
break;
}
}
while (true);
}
示例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) : "";
}
示例5: 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);
}
示例6: addSection
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的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;
}
示例7: addSection
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的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;
}
示例8: qualifySubstitutionGroup
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的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;
}
示例9: insertSchemaLocation
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* Inserts a schema location to the current ebics root element.
* @param namespaceURI the name space URI
* @param localPart the local part
* @param prefix the prefix
* @param value the value
*/
public void insertSchemaLocation(String namespaceURI,
String localPart,
String prefix,
String value)
{
XmlCursor cursor;
cursor = document.newCursor();
while (cursor.hasNextToken()) {
if (cursor.isStart()) {
cursor.toNextToken();
cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value);
break;
} else {
cursor.toNextToken();
}
}
}
示例10: moveToken
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
@SuppressWarnings( "unused" )
private void moveToken( int numToMove, XmlCursor xmlc )
{
for( int i = 0; i < Math.abs( numToMove ); i++ )
{
if( numToMove < 0 )
{
xmlc.toPrevToken();
}
else
{
xmlc.toNextToken();
}
}
}
示例11: skipNonElements
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param curs
* @return
*/
private static TokenType skipNonElements (XmlCursor curs)
{
TokenType tt = curs.currentTokenType();
while (tt.isComment() || tt.isProcinst())
{
tt = curs.toNextToken();
}
return tt;
}
示例12: moveSrcToDest
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param srcCurs
* @param destCurs
* @param fDontMoveIfSame
* @return
*/
private boolean moveSrcToDest (XmlCursor srcCurs, XmlCursor destCurs, boolean fDontMoveIfSame)
{
boolean fMovedSomething = true;
TokenType tt;
do
{
if (fDontMoveIfSame && srcCurs.isInSameDocument(destCurs) && (srcCurs.comparePosition(destCurs) == 0))
{
// If the source and destination are pointing at the same place then there's nothing to move.
fMovedSomething = false;
break;
}
// todo ***TLL*** Use replaceContents (when added) and eliminate children removes (see above todo).
if (destCurs.currentTokenType().isStartdoc())
{
destCurs.toNextToken();
}
// todo ***TLL*** Can Eric support notion of copy instead of me copying then moving???
XmlCursor copyCurs = copy(srcCurs);
copyCurs.moveXml(destCurs);
copyCurs.dispose();
tt = srcCurs.currentTokenType();
} while (!tt.isStart() && !tt.isEnd() && !tt.isEnddoc());
return fMovedSomething;
}
示例13: replace
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param destCurs
* @param newValue
*/
private void replace(XmlCursor destCurs, XML newValue)
{
if (destCurs.isStartdoc())
{
// Can't overwrite a whole document (user really wants to overwrite the contents of).
destCurs.toFirstContentToken();
}
// Orphan the token -- don't delete it outright on the XmlCursor.
removeToken(destCurs);
XmlCursor srcCurs = newValue.newCursor();
if (srcCurs.currentTokenType().isStartdoc())
{
// Cann't append a whole document (user really wants to append the contents of).
srcCurs.toFirstContentToken();
}
moveSrcToDest(srcCurs, destCurs, false);
// Re-link a new annotation to this cursor -- we just deleted the previous annotation on entrance to replace.
if (!destCurs.toPrevSibling())
{
destCurs.toPrevToken();
}
destCurs.setBookmark(new XScriptAnnotation(destCurs));
// todo would be nice if destCurs.toNextSibling went to where the next token if the cursor was pointing at the last token in the stream.
destCurs.toEndToken();
destCurs.toNextToken();
srcCurs.dispose();
}
示例14: changeNS
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
protected void changeNS (String oldURI, String newURI)
{
XmlCursor curs = newCursor();
while (curs.toParent()) {
/* Goto the top of the document */
}
TokenType tt = curs.currentTokenType();
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isStart())
{
do
{
if (tt.isStart() || tt.isAttr() || tt.isNamespace())
{
javax.xml.namespace.QName currQName = curs.getName();
if (oldURI.equals(currQName.getNamespaceURI()))
{
curs.setName(new javax.xml.namespace.QName(newURI, currQName.getLocalPart()));
}
}
tt = curs.toNextToken();
} while (!tt.isEnddoc() && !tt.isNone());
}
curs.dispose();
}
示例15: setAttribute
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param attrName
* @param value
*/
void setAttribute(XMLName xmlName, Object value)
{
if (xmlName.uri() == null &&
xmlName.localName().equals("*"))
{
throw ScriptRuntime.typeError("@* assignment not supported.");
}
XmlCursor curs = newCursor();
String strValue = ScriptRuntime.toString(value);
if (curs.currentTokenType().isStartdoc())
{
curs.toFirstContentToken();
}
javax.xml.namespace.QName qName;
try
{
qName = new javax.xml.namespace.QName(xmlName.uri(), xmlName.localName());
}
catch(Exception e)
{
throw ScriptRuntime.typeError(e.getMessage());
}
if (!curs.setAttributeText(qName, strValue))
{
if (curs.currentTokenType().isStart())
{
// Can only add attributes inside of a start.
curs.toNextToken();
}
curs.insertAttributeWithValue(qName, strValue);
}
curs.dispose();
}