Java Code Examples for org.apache.xmlbeans.XmlCursor#pop()
The following examples show how to use
org.apache.xmlbeans.XmlCursor#pop() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamespaceHelper.java From astor with GNU General Public License v2.0 | 6 votes |
public static void getNamespaces(XmlCursor cursor, Map prefixToURI) { cursor.push(); while(cursor.toNextToken().isAnyAttr()) { if(cursor.isNamespace()) { javax.xml.namespace.QName name = cursor.getName(); String prefix = name.getLocalPart(); String uri = name.getNamespaceURI(); prefixToURI.put(prefix, uri); } } cursor.pop(); }
Example 2
Source File: NamespaceHelper.java From astor with GNU General Public License v2.0 | 6 votes |
public static void removeNamespace(XmlCursor cursor, String prefix) { cursor.push(); while(cursor.toNextToken().isAnyAttr()) { if(cursor.isNamespace()) { javax.xml.namespace.QName name = cursor.getName(); if(name.getLocalPart().equals(prefix)) { cursor.removeXml(); break; } } } cursor.pop(); }
Example 3
Source File: XML.java From astor with GNU General Public License v2.0 | 5 votes |
/** * * @param cursor * @param opts * @return */ private static String dumpNode(XmlCursor cursor, XmlOptions opts) { if (cursor.isText()) return cursor.getChars(); if (cursor.isFinish()) return ""; cursor.push(); boolean wanRawText = cursor.isStartdoc() && !cursor.toFirstChild(); cursor.pop(); return wanRawText ? cursor.getTextValue() : cursor.xmlText( opts ); }
Example 4
Source File: NamespaceHelper.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example 5
Source File: NamespaceHelper.java From astor with GNU General Public License v2.0 | 5 votes |
/** * @return List of Namespace objects that are declared in the container pointed to by the cursor. */ public static Object[] namespaceDeclarations(XMLLibImpl lib, XmlCursor cursor) { ObjArray declarations = new ObjArray(); NamespaceHelper helper = new NamespaceHelper(lib); cursor.push(); int depth = 0; while(cursor.hasPrevToken()) { if(cursor.isContainer()) { cursor.push(); depth++; } cursor.toParent(); } for(int i = 0; i < depth - 1; i++) { cursor.pop(); helper.update(cursor, null); } if(depth > 0) { cursor.pop(); helper.update(cursor, declarations); } cursor.pop(); return declarations.toArray(); }
Example 6
Source File: NamespaceHelper.java From astor with GNU General Public License v2.0 | 5 votes |
/** * @return Prefix to URI map of all namespaces in scope at the cursor. */ public static Map getAllNamespaces(XMLLibImpl lib, XmlCursor cursor) { NamespaceHelper helper = new NamespaceHelper(lib); cursor.push(); int depth = 0; while(cursor.hasPrevToken()) { if(cursor.isContainer()) { cursor.push(); depth++; } cursor.toParent(); } for(int i = 0; i < depth; i++) { cursor.pop(); helper.update(cursor, null); } cursor.pop(); return helper.prefixToURI; }