All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.xolite.utils.XMLSkipper Maven / Gradle / Ivy

Go to download

This project provides a lightweight framework to serialize/deserialize (or marshall/unmarshall) java objects into XML. The implementation is based on standard SAX (Simple Api for Xml) but it follows a original approach based on the strong data encapsulation paradigm of Object Oriented (OO) programming.

The newest version!
/*-------------------------------------------------------------------------
 Copyright 2006 Olivier Berlanger

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -------------------------------------------------------------------------*/
package net.sf.xolite.utils;

import net.sf.xolite.XMLEventParser;
import net.sf.xolite.XMLParseException;
import net.sf.xolite.XMLSerializable;
import net.sf.xolite.XMLSerializeException;
import net.sf.xolite.XMLSerializer;


/**
 * XMLSerializable that allow to ignore a whole complex XML element during parsing.
 * 
 * @author Olivier Berlanger
 * @see XMLEventParser
 * @see XMLSerializer
 */
public class XMLSkipper implements XMLSerializable {


    private String elementUri;
    private String elementLocalName;


    public void startElement(String uri, String localName, XMLEventParser parser) throws XMLParseException {
        if (parser.isFirstEvent()) {
            elementUri = uri;
            elementLocalName = localName;
        }
    }


    public void endElement(String uri, String localName, XMLEventParser parser) throws XMLParseException {
    }


    /**
     * This object is not intended for serialization as it does not keep its XML content while parsing.
     */
    public void serialize(XMLSerializer serializer) throws XMLSerializeException {
        if (elementLocalName != null) {
            serializer.simpleElement(elementUri, elementLocalName, " ...(skipped)... ");
        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy