package net.xoetrope.xml.nanoxml;
import java.io.Reader;
import net.n3.nanoxml.IXMLElement;
import net.n3.nanoxml.IXMLParser;
import net.n3.nanoxml.IXMLReader;
import net.n3.nanoxml.NonValidator;
import net.n3.nanoxml.StdXMLBuilder;
import net.n3.nanoxml.StdXMLParser;
import net.n3.nanoxml.StdXMLReader;
import net.xoetrope.debug.DebugLogger;
import net.xoetrope.xml.XmlElement;
import net.xoetrope.xui.build.BuildProperties;
import net.xoetrope.xml.XmlParser;
/**
* A wrapper for the NanoXml Parser
* <p> Copyright (c) Xoetrope Ltd., 2002-2003</p>
* <p> $Revision: 2.2 $</p>
* <p> License: see License.txt</p>
*/
public class NanoXmlParser implements XmlParser
{
public NanoXmlParser()
{
}
/**
* Create a basic XmlElement of the type registered in the XmlParserFactory
* @param name The name of the new element
* @return The created XmlElement
*/
public XmlElement createXmlElement( String name )
{
return new NanoXmlElement( name );
}
/**
* Read the passed Reader object and parse its contents into an XmlElement
* structure of the type defined in the XmlParserFactory. Validate the parsed
* XML with the schema file located at the file indicated by the schemaSource
* parameter
* @param input The reader from which the content of the XML structure will be
* read
* @param schemaSource Location of the schema source which will be used to
* validate the parsed XML
* @return The root XmlElement resulting from the parsing of the XML
*/
public XmlElement parse( Reader input, String schemaSource )
{
return parse( input );
}
/**
* Read the passed Reader object and parse its contents into an XmlElement
* structure of the type defined in the XmlParserFactory.
* @param input The reader from which the content of the XML structure will be
* read
* @return The root XmlElement resulting from the parsing of the XML
*/
public XmlElement parse( Reader input )
{
IXMLElement xml = null;
try {
IXMLParser parser = new StdXMLParser();
parser.setBuilder( new StdXMLBuilder() );
parser.setValidator( new NonValidator() );
IXMLReader reader = new StdXMLReader( input );
parser.setReader( reader );
xml = ( IXMLElement )parser.parse();
}
catch ( Exception ex ) {
if ( BuildProperties.DEBUG ) {
DebugLogger.logError( "Unable to read/parse the xml: " + ex.getMessage());
ex.printStackTrace();
}
return null;
}
return new NanoXmlElement( xml );
}
}