Java 类javax.xml.stream.XMLStreamException 实例源码

项目:openjdk-jdk10    文件:XMLStreamReaderToXMLStreamWriter.java   
/**
 * Writes out the {@code i}-th attribute of the current element.
 *
 * <p>
 * Used from {@link #handleStartElement()}.
 */
protected void handleAttribute(int i) throws XMLStreamException {
    String nsUri = in.getAttributeNamespace(i);
    String prefix = in.getAttributePrefix(i);
     if (fixNull(nsUri).equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
         //Its a namespace decl, ignore as it is already written.
         return;
     }

    if(nsUri==null || prefix == null || prefix.equals("")) {
        out.writeAttribute(
            in.getAttributeLocalName(i),
            in.getAttributeValue(i)
        );
    } else {
        out.writeAttribute(
            prefix,
            nsUri,
            in.getAttributeLocalName(i),
            in.getAttributeValue(i)
        );
    }
}
项目:openjdk-jdk10    文件:JAXBMessage.java   
@Override
public XMLStreamReader readPayload() throws XMLStreamException {
   try {
        if(infoset==null) {
                            if (rawContext != null) {
                    XMLStreamBufferResult sbr = new XMLStreamBufferResult();
                                    Marshaller m = rawContext.createMarshaller();
                                    m.setProperty("jaxb.fragment", Boolean.TRUE);
                                    m.marshal(jaxbObject, sbr);
                    infoset = sbr.getXMLStreamBuffer();
                            } else {
                                MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
                                writePayloadTo(buffer.createFromXMLStreamWriter());
                                infoset = buffer;
                            }
        }
        XMLStreamReader reader = infoset.readAsXMLStreamReader();
        if(reader.getEventType()== START_DOCUMENT)
            XMLStreamReaderUtil.nextElementContent(reader);
        return reader;
    } catch (JAXBException e) {
       // bug 6449684, spec 4.3.4
       throw new WebServiceException(e);
    }
}
项目:rapidminer    文件:XlsxSheetContentParser.java   
/**
 * Closes the current open {@link XMLStreamReader} and creates a new one which starts the
 * reading process at the first row. It is assumed the the XLSX content and operator
 * configuration remain the same.
 *
 * @param factory
 *            the {@link XMLInputFactory} that should be used to open the
 *            {@link XMLStreamReader}.
 *
 * @throws IOException
 *             if an I/O error has occurred
 * @throws XMLStreamException
 *             if there are errors freeing associated XML reader resources or creating a new XML
 *             reader
 */
void reset(XMLInputFactory xmlFactory) throws IOException, XMLStreamException {

    // close open file and reader object
    close();

    // create new file and stream reader objects
    xlsxZipFile = new ZipFile(xlsxFile);
    ZipEntry workbookZipEntry = xlsxZipFile.getEntry(workbookZipEntryPath);
    if (workbookZipEntry == null) {
        throw new FileNotFoundException(
                "XLSX file is malformed. Reason: Selected workbook is missing in XLSX file. Path: "
                        + workbookZipEntryPath);
    }
    InputStream inputStream = xlsxZipFile.getInputStream(workbookZipEntry);
    reader = xmlFactory.createXMLStreamReader(new InputStreamReader(inputStream, encoding));

    // reset other variables
    currentRowIndex = -1;
    parsedRowIndex = -1;
    currentRowContent = null;
    nextRowWithContent = null;
    hasMoreContent = true;
    Arrays.fill(emptyColumn, true);
}
项目:freecol    文件:Settlement.java   
/**
 * {@inheritDoc}
 */
@Override
protected void readChild(FreeColXMLReader xr) throws XMLStreamException {
    final Specification spec = getSpecification();
    final String tag = xr.getLocalName();

    if (Ability.TAG.equals(tag)) {
        Ability ability = new Ability(xr, spec);
        if (ability.isIndependent()) addAbility(ability);

    } else if (Modifier.TAG.equals(tag)) {
        Modifier modifier = new Modifier(xr, spec);
        if (modifier.isIndependent()) addModifier(modifier);

    } else {
        super.readChild(xr);
    }
}
项目:FreeCol    文件:WorkerWish.java   
/**
 * {@inheritDoc}
 */
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
    super.readAttributes(xr);

    final AIMain aiMain = getAIMain();
    final Specification spec = getSpecification();

    // Delegated from Wish
    transportable = (xr.hasAttribute(TRANSPORTABLE_TAG))
        ? xr.makeAIObject(aiMain, TRANSPORTABLE_TAG,
                          AIUnit.class, (AIUnit)null, true)
        : null;

    unitType = xr.getType(spec, UNIT_TYPE_TAG,
                          UnitType.class, (UnitType)null);

    expertNeeded = xr.getAttribute(EXPERT_NEEDED_TAG, false);
}
项目:openjdk-jdk10    文件:DoubleXmlnsTest.java   
@Test
public void testDoubleXmlns() throws Exception {

    final String INVALID_XML = "<foo xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:xml='http://www.w3.org/XML/1998/namespace' ></foo>";

    try {
        XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(INVALID_XML));

        while (xsr.hasNext()) {
            xsr.next();
        }

        Assert.fail("Wellformedness error expected :" + INVALID_XML);
    } catch (XMLStreamException e) {
        ; // this is expected
    }
}
项目:openjdk-jdk10    文件:AnyTypeBeanInfo.java   
public void serializeBody(Object element, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
    NodeList childNodes = ((Element)element).getChildNodes();
    int len = childNodes.getLength();
    for( int i=0; i<len; i++ ) {
        Node child = childNodes.item(i);
        switch(child.getNodeType()) {
        case Node.CDATA_SECTION_NODE:
        case Node.TEXT_NODE:
            target.text(child.getNodeValue(),null);
            break;
        case Node.ELEMENT_NODE:
            target.writeDom((Element)child,domHandler,null,null);
            break;
        }
    }
}
项目:FreeCol    文件:FreeColXMLReader.java   
/**
 * Find a FreeCol AI object from an attribute in a stream.
 *
 * @param <T> The actual return type.
 * @param aiMain The {@code AIMain} that contains the object.
 * @param attributeName The attribute name.
 * @param returnClass The {@code AIObject} type to expect.
 * @param defaultValue The default value.
 * @param required If true a null result should throw an exception.
 * @exception XMLStreamException if there is problem reading the stream.
 * @return The {@code AIObject} found, or the default value if not.
 */
public <T extends AIObject> T findAIObject(AIMain aiMain,
    String attributeName, Class<T> returnClass, T defaultValue,
    boolean required) throws XMLStreamException {

    T ret = getAttribute(aiMain, attributeName, returnClass, (T)null);
    if (ret == (T)null) {
        if (required) {
            throw new XMLStreamException("Missing " + attributeName
                + " for " + returnClass.getName() + ": " + currentTag());
        } else {
            ret = defaultValue;
        }
    }
    return ret;
}
项目:powsybl-core    文件:LineXml.java   
@Override
protected void readSubElements(Line l, XmlReaderContext context) throws XMLStreamException {
    readUntilEndRootElement(context.getReader(), () -> {
        switch (context.getReader().getLocalName()) {
            case "currentLimits1":
                readCurrentLimits(1, l::newCurrentLimits1, context.getReader());
                break;

            case "currentLimits2":
                readCurrentLimits(2, l::newCurrentLimits2, context.getReader());
                break;

            default:
                super.readSubElements(l, context);
        }
    });
}
项目:OpenJSharp    文件:StreamReaderBufferCreator.java   
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
    storeStructure(T_DOCUMENT);

    _eventType = reader.next();
    while (_eventType != XMLStreamReader.END_DOCUMENT) {
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                storeElementAndChildren(reader);
                continue;
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
        _eventType = reader.next();
    }

    storeStructure(T_END);
}
项目:OpenJSharp    文件:XMLDOMWriterImpl.java   
/**
 * creates a DOM Element and appends it to the current element in the tree.
 * @param localName {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeStartElement(String localName) throws XMLStreamException {
    if(ownerDoc != null){
        Element element = ownerDoc.createElement(localName);
        if(currentNode!=null){
            currentNode.appendChild(element);
        }else{
            ownerDoc.appendChild(element);
        }
        currentNode = element;
    }
    if(needContextPop[depth]){
        namespaceContext.pushContext();
    }
    incDepth();
}
项目:powsybl-core    文件:VoltageLevelXml.java   
private void writeBusBreakerTopology(VoltageLevel vl, XmlWriterContext context) throws XMLStreamException {
    context.getWriter().writeStartElement(IIDM_URI, BUS_BREAKER_TOPOLOGY_ELEMENT_NAME);
    for (Bus b : vl.getBusBreakerView().getBuses()) {
        if (!context.getFilter().test(b)) {
            continue;
        }
        BusXml.INSTANCE.write(b, null, context);
    }
    for (Switch sw : vl.getBusBreakerView().getSwitches()) {
        Bus b1 = vl.getBusBreakerView().getBus1(context.getAnonymizer().anonymizeString(sw.getId()));
        Bus b2 = vl.getBusBreakerView().getBus2(context.getAnonymizer().anonymizeString(sw.getId()));
        if (!context.getFilter().test(b1) || !context.getFilter().test(b2)) {
            continue;
        }
        BusBreakerViewSwitchXml.INSTANCE.write(sw, vl, context);
    }
    context.getWriter().writeEndElement();
}
项目:OpenJSharp    文件:SAX2StAXEventWriter.java   
public void comment(char[] ch, int start, int length) throws SAXException {
    if (needToCallStartDocument) {
        // Drat. We were trying to postpone this until the first element so that we could get
        // the locator, but we can't output a comment before the start document, so we're just
        // going to have to do without the locator if it hasn't been set yet.
        writeStartDocument();
    }

    super.comment(ch, start, length);

    eventFactory.setLocation(getCurrentLocation());
    try {

        writer.add(eventFactory.createComment(new String(ch, start,
                length)));

    } catch (XMLStreamException e) {

        throw new SAXException(e);

    }

}
项目:powsybl-core    文件:ThreeWindingsTransformerXml.java   
@Override
protected void writeRootElementAttributes(ThreeWindingsTransformer twt, Substation s, XmlWriterContext context) throws XMLStreamException {
    XmlUtil.writeFloat("r1", twt.getLeg1().getR(), context.getWriter());
    XmlUtil.writeFloat("x1", twt.getLeg1().getX(), context.getWriter());
    XmlUtil.writeFloat("g1", twt.getLeg1().getG(), context.getWriter());
    XmlUtil.writeFloat("b1", twt.getLeg1().getB(), context.getWriter());
    XmlUtil.writeFloat("ratedU1", twt.getLeg1().getRatedU(), context.getWriter());
    XmlUtil.writeFloat("r2", twt.getLeg2().getR(), context.getWriter());
    XmlUtil.writeFloat("x2", twt.getLeg2().getX(), context.getWriter());
    XmlUtil.writeFloat("ratedU2", twt.getLeg2().getRatedU(), context.getWriter());
    XmlUtil.writeFloat("r3", twt.getLeg3().getR(), context.getWriter());
    XmlUtil.writeFloat("x3", twt.getLeg3().getX(), context.getWriter());
    XmlUtil.writeFloat("ratedU3", twt.getLeg3().getRatedU(), context.getWriter());
    writeNodeOrBus(1, twt.getLeg1().getTerminal(), context);
    writeNodeOrBus(2, twt.getLeg2().getTerminal(), context);
    writeNodeOrBus(3, twt.getLeg3().getTerminal(), context);
    if (context.getOptions().isWithBranchSV()) {
        writePQ(1, twt.getLeg1().getTerminal(), context.getWriter());
        writePQ(2, twt.getLeg2().getTerminal(), context.getWriter());
        writePQ(3, twt.getLeg3().getTerminal(), context.getWriter());
    }
}
项目:OperatieBRP    文件:ParserContext.java   
/**
 * Het volgende event dat verwerkt moet worden.
 *
 * @return het volgende event
 * @see javax.xml.stream.events.XMLEvent
 * @throws ParseException als het verwerken van het XML document fout gaat
 */
public int volgendeEvent() throws ParseException {
    try {
        return reader.next();
    } catch (XMLStreamException e) {
        throw new ParseException(FOUTMELDING, e);
    }
}
项目:FreeCol    文件:IntegerOption.java   
/**
 * {@inheritDoc}
 */
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
    super.readAttributes(xr);

    maximumValue = xr.getAttribute(MAXIMUM_VALUE_TAG, Integer.MAX_VALUE);

    minimumValue = xr.getAttribute(MINIMUM_VALUE_TAG, Integer.MIN_VALUE);

    value = limitValue(this.value);
}
项目:Excel2XML    文件:E2xCmdline.java   
/**
 * Writes out an XML cell based on coordinates and provided value
 * 
 * @param row
 *            the row index of the cell
 * @param col
 *            the column index
 * @param cellValue
 *            value of the cell, can be null for an empty cell
 * @param out
 *            the XML output stream
 * @param columns
 *            the Map with column titles
 */
private void writeAnyCell(final int row, final int col, final String cellValue, final XMLStreamWriter out,
        final Map<String, String> columns) {
    try {
        out.writeStartElement("cell");
        String colNum = String.valueOf(col);
        out.writeAttribute("row", String.valueOf(row));
        out.writeAttribute("col", colNum);
        if (columns.containsKey(colNum)) {
            out.writeAttribute("title", columns.get(colNum));
        }
        if (cellValue != null) {
            if (cellValue.contains("<") || cellValue.contains(">")) {
                out.writeCData(cellValue);
            } else {
                out.writeCharacters(cellValue);
            }
        } else {
            out.writeAttribute("empty", "true");
        }
        out.writeEndElement();

    } catch (XMLStreamException e) {
        e.printStackTrace();
    }

}
项目:DocIT    文件:Cut.java   
@Override
public void endElement(String uri, String name, String qName) {
    isSalary = false;
    try {
        writer.writeEndElement();
    } catch (XMLStreamException e) {
        e.printStackTrace();
    }
}
项目:rapidminer    文件:XlsxResultSet.java   
@Override
public void next(ProgressListener listener) throws OperatorException {
    try {
        worksheetParser.next(readMode);
    } catch (XMLStreamException | ParseException e) {
        throw new UserError(null, e, 321, configuration.getFile(), e.getMessage());
    }

    if (listener != null) {
        listener.setCompleted(getCurrentRow());
    }
}
项目:OpenJSharp    文件:StreamSOAPCodec.java   
public ContentType encode(Packet packet, OutputStream out) {
    if (packet.getMessage() != null) {
        String encoding = getPacketEncoding(packet);
        packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
        XMLStreamWriter writer = XMLStreamWriterFactory.create(out, encoding);
        try {
            packet.getMessage().writeTo(writer);
            writer.flush();
        } catch (XMLStreamException e) {
            throw new WebServiceException(e);
        }
        XMLStreamWriterFactory.recycle(writer);
    }
    return getContentType(packet);
}
项目:InComb    文件:AXMLParser.java   
/**
 * Reads the data from the {@link XMLEvent} and returns it. CData
 * will be handled special.
 * @param event {@link XMLEvent}
 * @param eventReader Reader for Reading {@link XMLEvent}
 * @return Character data from element
 * @throws XMLStreamException
 */
private String getCharacterData(XMLEvent event, final XMLEventReader eventReader) throws XMLStreamException {
    String result = "";
    event = eventReader.nextEvent();
    if (event instanceof Characters) {
        result = event.asCharacters().getData();
    }
    return result;
}
项目:freecol    文件:FreeColXMLReader.java   
/**
 * Seek to an identifier in this stream.
 *
 * @param id The identifier to find.
 * @return This {@code FreeColXMLReader} positioned such that the
 *     required identifier is current, or null on error or if not found.
 * @exception XMLStreamException if a problem was encountered
 *     during parsing.
 */
public FreeColXMLReader seek(String id) throws XMLStreamException {
    nextTag();
    for (int type = getEventType(); type != XMLEvent.END_DOCUMENT;
         type = getEventType()) {
        if (type == XMLEvent.START_ELEMENT
            && id.equals(readId())) return this;
        nextTag();
    }
    return null;
}
项目:freecol    文件:Tile.java   
/**
 * {@inheritDoc}
 */
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
    // Clear containers.
    settlement = null;

    super.readChildren(xr);
}
项目:FreeCol    文件:FreeColModFile.java   
/**
 * Reads a file object representing this mod.
 *
 * @exception IOException if thrown while reading the "mod.xml" file.
 */
protected void readModDescriptor() throws IOException {
    try (
        FreeColXMLReader xr
            = new FreeColXMLReader(getModDescriptorInputStream());
    ) {
        xr.nextTag();
        id = xr.readId();
        parent = xr.getAttribute("parent", (String)null);
    } catch (XMLStreamException xse) {
        throw new IOException(xse);
    }
}
项目:freecol    文件:PlunderType.java   
/**
 * {@inheritDoc}
 */
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
    super.readAttributes(xr);

    this.plunder = new RandomRange(xr);
}
项目:OpenJSharp    文件:StAXEvent2SAX.java   
private void handleCharacters(Characters event) throws XMLStreamException {
    try {
        _sax.characters(
            event.getData().toCharArray(),
            0,
            event.getData().length());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
项目:Equella    文件:XMLStreamer.java   
public void writeData(String data)
{
    try
    {
        xml.writeCharacters(data);
    }
    catch( XMLStreamException ex )
    {
        throw new RuntimeException(ex);
    }
}
项目:OpenJSharp    文件:XMLDOMWriterImpl.java   
/**
 * creates a DOM Element and appends it to the current element in the tree.
 * @param namespaceURI {@inheritDoc}
 * @param localName {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
    if(ownerDoc != null){
        String qualifiedName = null;
        String prefix = null;

        if(namespaceURI == null ){
            throw new XMLStreamException("NamespaceURI cannot be null");
        }
        if(localName == null){
            throw new XMLStreamException("Local name cannot be null");
        }

        if(namespaceContext != null){
            prefix = namespaceContext.getPrefix(namespaceURI);
        }
        if(prefix == null){
            throw new XMLStreamException("Namespace URI "+namespaceURI +
                    "is not bound to any prefix" );
        }
        if("".equals(prefix)){
            qualifiedName = localName;
        }else{
            qualifiedName =  getQName(prefix,localName);
        }

        Element element = ownerDoc.createElementNS(namespaceURI, qualifiedName);

        if(currentNode!=null){
            currentNode.appendChild(element);
        }else{
            ownerDoc.appendChild(element);
        }
        currentNode = element;
    }
    if(needContextPop[depth]){
        namespaceContext.pushContext();
    }
    incDepth();
}
项目:freecol    文件:TransportMission.java   
/**
 * {@inheritDoc}
 */
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
    // Clear containers.
    tClear();

    super.readChildren(xr);
}
项目:openjdk-jdk10    文件:SaajStaxWriter.java   
@Override
public void writeCharacters(final String text) throws XMLStreamException {
    currentElement = deferredElement.flushTo(currentElement);
    try {
        currentElement.addTextNode(text);
    } catch (SOAPException e) {
        throw new XMLStreamException(e);
    }
}
项目:openjdk-jdk10    文件:SaajStaxWriterEx.java   
@Override
public void writeStartElement(String prefix, String ln, String ns) throws XMLStreamException {
    if (xopNS.equals(ns) && Include.equals(ln)) {
        state = State.xopInclude;
        return;
    } else {
        super.writeStartElement(prefix, ln, ns);
    }
}
项目:powsybl-core    文件:TieLineXml.java   
@Override
protected void writeRootElementAttributes(TieLine tl, Network n, XmlWriterContext context) throws XMLStreamException {
    context.getWriter().writeAttribute("ucteXnodeCode", tl.getUcteXnodeCode());
    writeNodeOrBus(1, tl.getTerminal1(), context);
    writeNodeOrBus(2, tl.getTerminal2(), context);
    if (context.getOptions().isWithBranchSV()) {
        writePQ(1, tl.getTerminal1(), context.getWriter());
        writePQ(2, tl.getTerminal2(), context.getWriter());
    }
    writeHalf(tl.getHalf1(), context, 1);
    writeHalf(tl.getHalf2(), context, 2);
}
项目:FreeCol    文件:Colony.java   
/**
 * {@inheritDoc}
 */
@Override
public void readChild(FreeColXMLReader xr) throws XMLStreamException {
    final Specification spec = getSpecification();
    final Game game = getGame();
    final String tag = xr.getLocalName();

    if (BUILD_QUEUE_TAG.equals(tag)) {
        BuildableType bt = xr.getType(spec, ID_ATTRIBUTE_TAG,
                BuildableType.class, (BuildableType)null);
        if (bt != null) buildQueue.add(bt);
        xr.closeTag(BUILD_QUEUE_TAG);

    } else if (POPULATION_QUEUE_TAG.equals(xr.getLocalName())) {
        UnitType ut = xr.getType(spec, ID_ATTRIBUTE_TAG,
                UnitType.class, (UnitType)null);
        if (ut != null) populationQueue.add(ut);
        xr.closeTag(POPULATION_QUEUE_TAG);

    } else if (Building.TAG.equals(tag)) {
        addBuilding(xr.readFreeColObject(game, Building.class));

    } else if (ColonyTile.TAG.equals(tag)) {
        addColonyTile(xr.readFreeColObject(game, ColonyTile.class));

    } else if (ExportData.TAG.equals(tag)) {
        ExportData data = new ExportData(xr);
        setExportData(data);

    } else {
        super.readChild(xr);
    }
}
项目:openjdk-jdk10    文件:ExceptionTest.java   
@Test
public void testException() {

    final String EXPECTED_OUTPUT = "Test XMLStreamException";
    try {
        Exception ex = new IOException("Test XMLStreamException");
        throw new XMLStreamException(ex);
    } catch (XMLStreamException e) {
        Assert.assertTrue(e.getMessage().contains(EXPECTED_OUTPUT), "XMLStreamException does not contain the message " + "of the wrapped exception");
    }
}
项目:openjdk-jdk10    文件:TransformerTestTemplate.java   
public StAXSource getStAXSource(XMLInputFactory xif)
    throws XMLStreamException
{
    return new StAXSource(
        xif.createXMLStreamReader(new StringReader(sourceXml))
    );
}
项目:OpenJSharp    文件:XMLSerializer.java   
/**
 * Switches to the "marshal child texts/elements" mode.
 * This method has to be called after the 1st pass is completed.
 */
public void endAttributes() throws SAXException, IOException, XMLStreamException  {
    if(!seenRoot) {
        seenRoot = true;
        if(schemaLocation!=null || noNsSchemaLocation!=null) {
            int p = nsContext.getPrefixIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE);
            if(schemaLocation!=null)
                out.attribute(p,"schemaLocation",schemaLocation);
            if(noNsSchemaLocation!=null)
                out.attribute(p,"noNamespaceSchemaLocation",noNsSchemaLocation);
        }
    }

    out.endStartTag();
}
项目:openjdk-jdk10    文件:InlineBinaryTransducer.java   
@Override
public void writeText(XMLSerializer w, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    boolean old = w.setInlineBinaryFlag(true);
    try {
        core.writeText(w,o,fieldName);
    } finally {
        w.setInlineBinaryFlag(old);
    }
}
项目:FreeCol    文件:DefendSettlementMission.java   
/**
 * {@inheritDoc}
 */
@Override
protected void writeAttributes(FreeColXMLWriter xw) throws XMLStreamException {
    super.writeAttributes(xw);

    if (target != null) {
        xw.writeAttribute(SETTLEMENT_TAG, target.getId());
    }
}
项目:freecol    文件:UnitLocation.java   
/**
 * {@inheritDoc}
 */
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
    // Clear containers.
    clearUnitList();

    super.readChildren(xr);
}
项目:OpenJSharp    文件:StreamReaderBufferProcessor.java   
public final String getElementText(boolean startElementRead) throws XMLStreamException {
    if (!startElementRead) {
        throw new XMLStreamException("");
    }

    int eventType = getEventType();
    StringBuilder content = new StringBuilder();
    while(eventType != END_ELEMENT ) {
        if(eventType == CHARACTERS
                || eventType == CDATA
                || eventType == SPACE
                || eventType == ENTITY_REFERENCE) {
            content.append(getText());
        } else if(eventType == PROCESSING_INSTRUCTION
                || eventType == COMMENT) {
            // skipping
        } else if(eventType == END_DOCUMENT) {
            throw new XMLStreamException("");
        } else if(eventType == START_ELEMENT) {
            throw new XMLStreamException("");
        } else {
            throw new XMLStreamException("");
        }
        eventType = next();
    }
    return content.toString();
}