本文整理汇总了Java中org.apache.xmlbeans.XmlCursor.toFirstAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor.toFirstAttribute方法的具体用法?Java XmlCursor.toFirstAttribute怎么用?Java XmlCursor.toFirstAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xmlbeans.XmlCursor
的用法示例。
在下文中一共展示了XmlCursor.toFirstAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verify_condition
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private boolean verify_condition(XmlCursor cursor, Condition condition) {
boolean more, found=false;
XmlBookmark bookmark = new XmlBookmark(){};
cursor.setBookmark(bookmark);
if (condition.isAttribute) {
for (more=cursor.toFirstAttribute(); more&&!found; more=cursor.toNextAttribute()) {
if (cursor.getName().getLocalPart().equals(condition.name)) {
found = cursor.getTextValue().trim().equals(condition.value);
}
}
} else {
for (more=cursor.toFirstChild(); more&&!found; more=cursor.toNextSibling()) {
if (cursor.getName().getLocalPart().equals(condition.name)) {
found = cursor.getTextValue().trim().equals(condition.value);
}
}
}
cursor.toBookmark(bookmark);
return found;
}
示例2: matchAttributes
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param name
* @return
*/
private XMLList matchAttributes(XMLName xmlName)
{
XMLList result = new XMLList(lib);
XmlCursor curs = newCursor();
if (curs.currentTokenType().isStartdoc())
{
curs.toFirstContentToken();
}
if (curs.isStart())
{
if (curs.toFirstAttribute())
{
do
{
if (qnameMatches(xmlName, curs.getName()))
{
result.addToList(createAttributeObject(curs));
}
} while (curs.toNextAttribute());
}
}
curs.dispose();
return result;
}
示例3: deleteXMLProperty
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param name
*/
void deleteXMLProperty(XMLName name)
{
if (!name.isDescendants() && name.isAttributeName())
{
XmlCursor curs = newCursor();
// TODO: Cover the case *::name
if (name.localName().equals("*"))
{
// Delete all attributes.
if (curs.toFirstAttribute())
{
while (curs.currentTokenType().isAttr())
{
curs.removeXml();
}
}
}
else
{
// Delete an attribute.
javax.xml.namespace.QName qname = new javax.xml.namespace.QName(
name.uri(), name.localName());
curs.removeAttribute(qname);
}
curs.dispose();
}
else
{
XMLList matches = getPropertyList(name);
matches.remove();
}
}
示例4: update
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* Updates the internal state of this NamespaceHelper with the
* namespace information of the element pointed to by the cursor.
*/
private void update(XmlCursor cursor, ObjArray declarations)
{
// Process the Namespace declarations
cursor.push();
while(cursor.toNextToken().isAnyAttr())
{
if(cursor.isNamespace())
{
javax.xml.namespace.QName name = cursor.getName();
String prefix = name.getLocalPart();
String uri = name.getNamespaceURI();
declareNamespace(prefix, uri, declarations);
}
}
cursor.pop();
// Process the element
processName(cursor, declarations);
// Process the attributes
cursor.push();
boolean hasNext = cursor.toFirstAttribute();
while(hasNext)
{
processName(cursor, declarations);
hasNext = cursor.toNextAttribute();
}
cursor.pop();
}
示例5: assertAttributesEqual
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* Compares the attributes of the elements at the current position of two XmlCursors.
* The ordering of the attributes is ignored in the comparison. Fails the JUnit test
* case if the attributes or their values are different.
*
* @param message to display on test failure (may be null)
* @param expected
* @param actual
*/
private static void assertAttributesEqual(String message, XmlCursor expected, XmlCursor actual)
{
Map<QName,String> map1 = new HashMap<QName,String>();
Map<QName,String> map2 = new HashMap<QName,String>();
boolean attr1 = expected.toFirstAttribute();
boolean attr2 = actual.toFirstAttribute();
if (attr1 != attr2)
{
if (expected.isAttr() || actual.isAttr())
{
expected.toParent();
}
fail(message, "Differing number of attributes for element: '" + QNameHelper.pretty(expected.getName()) + "'");
}
else if (!attr1)
{
return;
}
else
{
map1.put(expected.getName(), expected.getTextValue());
map2.put(actual.getName(), actual.getTextValue());
}
while (true)
{
attr1 = expected.toNextAttribute();
attr2 = actual.toNextAttribute();
if (attr1 != attr2)
{
if (expected.isAttr() || actual.isAttr())
{
expected.toParent();
}
fail(message, "Differing number of attributes for element: '" + QNameHelper.pretty(expected.getName()) + "'");
}
else if (!attr1)
{
break;
}
else
{
map1.put(expected.getName(), expected.getTextValue());
map2.put(actual.getName(), actual.getTextValue());
}
}
expected.toParent();
actual.toParent();
// check that attribute maps match, neglecting order
Iterator<QName> iter = map1.keySet().iterator();
while (iter.hasNext())
{
QName name = iter.next();
String value1 = map1.get(name);
String value2 = map2.get(name);
if (value2 == null)
{
fail(message, "Expected attribute value missing for element: "
+ QNameHelper.pretty(expected.getName()) + "--> '" + name + "'");
}
else if (!value2.equals(value1))
{
fail(message, "Attribute values for element '" + QNameHelper.pretty(expected.getName())
+ "': Expected '" + value1 + "', Actual '" + value2 + "'");
}
}
}