/** * Add the xml:spaces="preserve" attribute if the string has leading or trailing spaces * * @param xs the string to check */ protected static void preserveSpaces(STXstring xs) { String text = xs.getStringValue(); if (text != null && text.length() > 0) { char firstChar = text.charAt(0); char lastChar = text.charAt(text.length() - 1); if(Character.isWhitespace(firstChar) || Character.isWhitespace(lastChar)) { XmlCursor c = xs.newCursor(); c.toNextToken(); c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); c.dispose(); } } }
/** * Add the xml:spaces="preserve" attribute if the string has leading or trailing white spaces * * @param xs the string to check */ static void preserveSpaces(XmlString xs) { String text = xs.getStringValue(); if (text != null && (text.startsWith(" ") || text.endsWith(" "))) { XmlCursor c = xs.newCursor(); c.toNextToken(); c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); c.dispose(); } }
protected void write(OutputStream out) throws IOException { XmlObject rootObject = XmlObject.Factory.newInstance(); XmlCursor rootCursor = rootObject.newCursor(); rootCursor.toNextToken(); rootCursor.beginElement("xml"); for(int i=0; i < _items.size(); i++){ XmlCursor xc = _items.get(i).newCursor(); rootCursor.beginElement(_qnames.get(i)); while(xc.toNextToken() == XmlCursor.TokenType.ATTR) { Node anode = xc.getDomNode(); rootCursor.insertAttributeWithValue(anode.getLocalName(), anode.getNamespaceURI(), anode.getNodeValue()); } xc.toStartDoc(); xc.copyXmlContents(rootCursor); rootCursor.toNextToken(); xc.dispose(); } rootCursor.dispose(); rootObject.save(out, DEFAULT_XML_OPTIONS); }
/** * The low level code to insert {@code <c:chart>} tag into * {@code<a:graphicData>}. * * Here is the schema (ECMA-376): * <pre> * {@code * <complexType name="CT_GraphicalObjectData"> * <sequence> * <any minOccurs="0" maxOccurs="unbounded" processContents="strict"/> * </sequence> * <attribute name="uri" type="xsd:token"/> * </complexType> * } * </pre> */ private void appendChartElement(CTGraphicalObjectData data, String id) { String r_namespaceUri = STRelationshipId.type.getName().getNamespaceURI(); String c_namespaceUri = XSSFDrawing.NAMESPACE_C; XmlCursor cursor = data.newCursor(); cursor.toNextToken(); cursor.beginElement(new QName(c_namespaceUri, "chart", "c")); cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id); cursor.dispose(); data.setUri(c_namespaceUri); }
protected static void insertXChild(XmlObject root, XmlObject child) { XmlCursor rootCursor = root.newCursor(); rootCursor.toEndToken(); XmlCursor childCursor = child.newCursor(); childCursor.toNextToken(); childCursor.moveXml(rootCursor); childCursor.dispose(); rootCursor.dispose(); }
TokenType t = cursor.toNextToken(); if (t.isText()) { sb.append(cursor.getTextValue());
static CTGraphicalObjectFrame prototype(int shapeId){ CTGraphicalObjectFrame frame = CTGraphicalObjectFrame.Factory.newInstance(); CTGraphicalObjectFrameNonVisual nvGr = frame.addNewNvGraphicFramePr(); CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr(); cnv.setName("Table " + shapeId); cnv.setId(shapeId); nvGr.addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoGrp(true); nvGr.addNewNvPr(); frame.addNewXfrm(); CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); XmlCursor grCur = gr.newCursor(); grCur.toNextToken(); grCur.beginElement(new QName(XSLFRelation.NS_DRAWINGML, "tbl")); CTTable tbl = CTTable.Factory.newInstance(); tbl.addNewTblPr(); tbl.addNewTblGrid(); XmlCursor tblCur = tbl.newCursor(); tblCur.moveXmlContents(grCur); tblCur.dispose(); grCur.dispose(); gr.setUri(TABLE_URI); return frame; }
private void moveToken(int numToMove, XmlCursor xmlc) { for (int i = 0; i < Math.abs(numToMove); i++) { if (numToMove < 0) { xmlc.toPrevToken(); } else { xmlc.toNextToken(); } } }
private void processElement(SchemaParticle sp, XmlCursor xmlc, boolean mixed) { // cast as schema local element SchemaLocalElement element = (SchemaLocalElement) sp; /// ^ -> <elemenname></elem>^ if (_soapEnc) xmlc.insertElement(element.getName().getLocalPart()); // soap encoded? drop namespaces. else xmlc.insertElement(element.getName().getLocalPart(), element.getName().getNamespaceURI()); _nElements++; /// -> <elem>^</elem> xmlc.toPrevToken(); // -> <elem>stuff^</elem> createSampleForType(element.getType(), xmlc); // -> <elem>stuff</elem>^ xmlc.toNextToken(); }
public void processDoc(XmlObject[] instances, Inst2XsdOptions options, TypeSystemHolder typeSystemHolder) { for (int i = 0; i < instances.length; i++) { XmlObject instance = instances[i]; XmlCursor xc = instance.newCursor(); // xc on start doc StringBuffer comment = new StringBuffer(); while( !xc.isStart() ) { xc.toNextToken(); if( xc.isComment() ) comment.append(xc.getTextValue()); else if (xc.isEnddoc()) return; } // xc now on the root element Element withElem = processElement(xc, comment.toString(), options, typeSystemHolder); withElem.setGlobal(true); addGlobalElement(withElem, typeSystemHolder, options); } }
int token = c.toNextToken().intValue(); if (!Locale.isWhiteSpace(c.getChars())) return true; token = c.toNextToken().intValue(); break SWITCH; case TokenType.INT_COMMENT: case TokenType.INT_PROCINST: token = c.toNextToken().intValue(); break SWITCH;
private XmlObject objectAtDistance(int count) { XmlCursor cur = _root.newCursor(); while (count > 0) { cur.toNextToken(); if (!cur.currentTokenType().isNamespace()) { count -= 1; // System.out.println("Count: " + count + " " + cur.currentTokenType().toString() + " " + QName.pretty(cur.getName())); } } XmlObject result = cur.getObject(); cur.dispose(); return result; } }
XmlCursor.TokenType tt = xc.toNextToken(); switch (tt.intValue())
private static void positionEnvironment(XmlCursor cursor) { XmlCursor.TokenType token; while ((token = cursor.toNextToken()) != XmlCursor.TokenType.START && token != XmlCursor.TokenType.END) { //keep going } }
private XmlObject ensureStore() { if ((_flags & FLAG_STORE) != 0) return this; check_dated(); String value = (_flags & FLAG_NIL) != 0 ? "" : compute_text( has_store() ? get_store() : null ); XmlOptions options = new XmlOptions().setDocumentType(schemaType()); XmlObject x = XmlObject.Factory.newInstance( options ); XmlCursor c = x.newCursor(); c.toNextToken(); c.insertChars( value ); return x; }
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. XmlOptions options = new XmlOptions(); options.put(XmlOptions.SAVE_PRETTY_PRINT); options.put(XmlOptions.SAVE_PRETTY_PRINT_INDENT, 2); options.put(XmlOptions.SAVE_AGGRESSIVE_NAMESPACES); String result = object.xmlText(options); return result; }
/** * Computes how many text nodes the * @param c the position in the document * @return how many text nodes occur before the position determined by <code>c</code> */ private static int countTextTokens(XmlCursor c) { int k = 0; int l = 0; XmlCursor d = c.newCursor(); c.push(); c.toParent(); TokenType tt = c.toFirstContentToken(); while (!tt.isEnd()) { if (tt.isText()) { if (c.comparePosition(d) > 0) // We have moved after the initial position l++; else k++; } else if (tt.isStart()) c.toEndToken(); tt = c.toNextToken(); } c.pop(); return l == 0 ? 0 : k; }
c.toParent(); c.toParent(); c.toNextToken(); // on the "xmlns:ns" attribute c.push(); System.out.println(generateXPath(c, d, ns)); c.pop(); c.push(); System.out.println(generateXPath(c, null, ns)); c.pop();
XmlCursor cursor= targetObject.newCursor(); cursor.toNextToken(); cursor.insertNamespace("A", "namespace1"); //For example cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); cursor.dispose();
public static BaseNotificationType extractBaseNotificationType(XmlObject xmldata) { XmlCursor c = xmldata.newCursor(); c.toNextToken(); BaseNotificationType type = (BaseNotificationType) c.getObject(); c.dispose(); return type; }