libnanoxml2-java-2.2.3.dfsg/ 0000755 0001750 0001750 00000000000 07616770720 016076 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/ThirdParty/ 0000755 0001750 0001750 00000000000 07616770707 020175 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/ThirdParty/SAX/ 0000755 0001750 0001750 00000000000 11045140126 020601 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/Documentation/ 0000755 0001750 0001750 00000000000 07616770707 020714 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/ 0000755 0001750 0001750 00000000000 11045140126 023034 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/ 0000755 0001750 0001750 00000000000 11045140126 024011 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/introduction.tex 0000644 0001750 0001750 00000010734 07616770720 027303 0 ustar sveinung sveinung \chapter{Introduction}
This chapter gives a short introduction to XML and NanoXML.
\section{About \ltext{XML}}
The extensible markup language,
\href{http://www.w3c.org/TR/REC-xml}{\ltext{XML}}, is a way to mark up text in
a structured document.
\ltext{XML} is a simplification of the complex \ltext{SGML} standard.
\ltext{SGML}, the Standard Generalized Markup Language, is an international
(\ltext{ISO}) standard for marking up text and graphics.
The best known application of \ltext{SGML} is \ltext{HTML}.
Although \ltext{SGML} data is very easy to write, it's very difficult to write a
generic \ltext{SGML} parser.
When designing \ltext{XML} however, the authors removed much of the flexibility
of \ltext{SGML} making it much easier to parse \ltext{XML} documents correctly.
\ltext{XML} data is structured as a tree of \term{entities}.
An entity can be a string of character data or an element which can contain other
entities.
Elements can optionally have a set of attributes.
Attributes are key/value pairs which set some properties of an element.
The following example shows some XML data:
\begin{example}
$<$book$>$
~~$<$chapter id="my chapter"$>$
~~~~$<$title$>$The title$<$/title$>$
~~~~Some text.
~~$<$/chapter$>$
$<$/book$>$
\end{example}
At the root of the tree, you can find the element ``book''.
This element contains one child element: ``chapter''.
The chapter element has one attribute which maps the key ``id'' to
``my chapter''.
The chapter element has two child entities: the element ``title'' and the
character data ``Some text.''.
Finally, the title element has one child, the string ``The title''.
\section{About \ltext{NanoXML}}
In April 2000, \ltext{NanoXML} was first released as a spin-off project of
\ltext{AUIT}, the Abstract User Interface Toolkit.
The intent of NanoXML was to be a small parser which was easy to use.
\ltext{SAX} and \ltext{DOM} are much too complex for what I needed and the
mainstream parsers were either much too big or had a very restrictive license.
\ltext{NanoXML 1} has all the features I needed: it is very small (about 6K),
is reasonably fast for small \ltext{XML} documents, is very easy to use and is
free (\ltext{zlib/libpng} license).
As I never intended to use \ltext{NanoXML} to parse \ltext{DocBook} documents,
there was no support for mixed data or \ltext{DTD} parsing.
\ltext{NanoXML} was released as a \ltext{SourceForge} project and, because of the
very good response from its users, it matured to a small and stable parser.
The final version, release \ltext{1.6.8} was released in May 2001.
Because of its small size, people started to use \ltext{NanoXML} for embedded
systems (\ltext{KVM}, \ltext{J2ME}) and kindly submitted patches to make
\ltext{NanoXML} work in such restricted environment.
\section{\ltext{NanoXML} 2}
In July 2001, \ltext{NanoXML} 2 has been released.
Unlike \ltext{NanoXML 1}, speed and \ltext{XML} compliancy were considered to be
very important when the new parser was designed.
\ltext{NanoXML 2} is also very modular: you can easily replace the different
components in the parser to customize it to your needs.
The modularity of \ltext{NanoXML 2} also benefits extensions like \acronym{e.g.}
\ltext{SAX} support which can now directly access the parser.
In \ltext{NanoXML 1}, the \ltext{SAX} adapter had to iterate the data structure
built by the base product.
Although many features were added to \ltext{NanoXML}, the second release was
still very small.
The full parser with builder fits in a \ltext{JAR} file of about 32K.
This is still very tiny, especially when you compare this with the ``standard''
parsers of more than four times its size.
As there is still need for a tiny parser like \ltext{NanoXML 1}, there is a
special branch of \ltext{NanoXML 2}: \ltext{NanoXML/Lite}. This parser is source
compatible with \ltext{NanoXML 1} but features a new parsing algorithm which
makes it more than twice as fast as the older version.
It is however more restrictive on the \ltext{XML} data it parses: the older
version allowed some not-wellformed data to be parsed.
There are three branches of NanoXML 2:
\begin{itemize}
\item[$\bullet$]
\term{NanoXML/Lite} is the successor of \ltext{NanoXML 1}.
It features an almost compatible parser which is extremely small.
\item[$\bullet$]
\term{NanoXML/Java} is the standard parser.
\item[$\bullet$]
\term{NanoXML/SAX} is the \ltext{SAX} adapter for \ltext{NanoXML/Java}.
\end{itemize}
The latest version of \ltext{NanoXML} is \ltext{NanoXML 2.2.1}, which has been
released in February 2002.
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/NanoXML-Lite.tex 0000644 0001750 0001750 00000001016 07616770720 026722 0 ustar sveinung sveinung \documentclass[a4paper]{book}
\usepackage{hyperref}
\title{NanoXML/Lite 2.2}
\author{Marc De Scheemaecker $<$cyberelf@mac.com$>$}
\pdfinfo {
/Title (NanoXML/Lite 2.2)
/Creator (LaTeX)
/Producer (pdfTeX 0.14a)
/Author (Marc De Scheemaecker)
/CreationDate (D:20010204000000)
/ModDate (D:20030201171156)
/Subject (NanoXML/Lite)
/Keywords (NanoXML,XML)
}
\include{defs}
\begin{document}
\titlepage
\maketitle
\tableofcontents
\include{introduction}
\include{retrieving_data}
\end{document}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/retrieving_data.tex 0000644 0001750 0001750 00000011245 07616770720 027727 0 ustar sveinung sveinung \chapter{Retrieving Data From An \ltext{XML} Datasource}
This chapter shows how to retrieve \ltext{XML} data from a standard data source.
Such source can be a file, an \ltext{HTTP} object or a text string.
\section{A Very Simple Example}
This section describes a very simple \ltext{XML} application.
It parses \ltext{XML} data from a stream and dumps it to the standard output.
While its use is very limited, it shows how to set up a parser and parse an
\ltext{XML} document.
\begin{example}
\xkeyword{import} nanoxml.*;\xcallout{1}
\xkeyword{import} java.io.*;
\xkeyword{public class} DumpXML
\{
~~\xkeyword{public static void} main(String[] args)
~~~~\xkeyword{throws} Exception
~~\{
~~~~XMLElement xml = new XMLElement();\xcallout{2}
~~~~FileReader reader = new FileReader("test.xml");
~~~~xml.parseFromReader(reader);\xcallout{3}
~~~~System.out.println(xml);\xcallout{4}
~~\}
\}
\end{example}
\begin{callout}
\coitem
The \ltext{NanoXML} classes are located in the package \packagename{nanoxml}.
\coitem
This command creates an empty \ltext{XML} element.
\coitem
The method \methodname{parseFromReader} parses the data in the file
\filename{test.xml} and fills the empty element.
\coitem
The \ltext{XML} element is dumped to the standard output.
\end{callout}
\section{Analyzing The Data}
You can easily traverse the logical tree generated by the parser.
By calling one of the \methodname{parse*} methods, you fill an empty
\ltext{XML} element with the parsed contents.
Every such object can have a name, attributes, \ltext{\#PCDATA} content and child
objects.
The following XML data:
\begin{example}
$<$FOO attr1="fred" attr2="barney"$>$
~~$<$BAR a1="flintstone" a2="rubble"$>$
~~~~Some data.
~~$<$/BAR$>$
~~$<$QUUX/$>$
$<$/FOO$>$
\end{example}
is parsed to the following objects:
\begin{itemize}
\item[] Element FOO:
\begin{itemize}
\item[] Attributes = \{ "attr1"="fred", "attr2"="barney" \}
\item[] Children = \{ BAR, QUUX \}
\item[] PCData = null
\end{itemize}
\item[] Element BAR:
\begin{itemize}
\item[] Attributes = \{ "a1"="flintstone", "a2"="rubble" \}
\item[] Children = \{\}
\item[] PCData = "Some data."
\end{itemize}
\item[] Element QUUX:
\begin{itemize}
\item[] Attributes = \{\}
\item[] Children = \{\}
\item[] PCData = null
\end{itemize}
\end{itemize}
You can retrieve the name of an element using the method \methodname{getName},
thus:
\begin{example}
FOO.getName() $\to$ "FOO"
\end{example}
You can enumerate the attribute names using the method
\methodname{enumerateAttributeNames}:
\begin{example}
Enumeration enum = FOO.enumerateAttributeNames();
\xkeyword{while} (enum.hasMoreElements()) \{
~~System.out.print(enum.nextElement());
~~System.out.print(' ');
\}
$\to$ attr1 attr2
\end{example}
You can retrieve the value of an attribute using \methodname{getAttribute}:
\begin{example}
FOO.getAttribute("attr1") $\to$ "fred"
\end{example}
The child elements can be enumerated using the method
\methodname{enumerateChildren}:
\begin{example}
Enumeration enum = FOO.enumerateChildren();
\xkeyword{while} (enum.hasMoreElements()) \{
~~XMLElement child = (XMLElement) enum.nextElement();
~~System.out.print(child.getName() + ' ');
\}
$\to$ BAR QUUX
\end{example}
If the element contains parsed character data (\ltext{\#PCDATA}) as its only
child.
You can retrieve that data using \methodname{getContent}:
\begin{example}
BAR.getContent() $\to$ "Some data."
\end{example}
Note that in \ltext{NanoXML/Lite}, a child cannot have children and
\ltext{\#PCDATA} content at the same time.
\section{Generating \ltext{XML}}
You can very easily create a tree of \ltext{XML} elements or modify an existing
one.
To create a new tree, just create an \classname{XMLElement} object:
\begin{example}
XMLElement elt = new XMLElement("ElementName");
\end{example}
You can add an attribute to the element by calling \methodname{setAttribute}:
\begin{example}
elt.setAttribute("key", "value");
\end{example}
You can add a child element to an element by calling \methodname{addChild}:
\begin{example}
XMLElement child = new XMLElement("Child");
elt.addChild(child);
\end{example}
If an element has no children, you can add \ltext{\#PCDATA} content to it using
\methodname{setContent}:
\begin{example}
child.setContent("Some content");
\end{example}
Note that in \ltext{NanoXML/Lite}, a child cannot have children and
\ltext{\#PCDATA} content at the same time.
When you have created or edited the \ltext{XML} element tree, you can write it
out to an output stream or writer using the method \methodname{toString}:
\begin{example}
java.io.PrintWriter output = ...;
XMLElement xmltree = ...;
output.println(xmltree);
\end{example}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/defs.tex 0000644 0001750 0001750 00000001343 07616770720 025477 0 ustar sveinung sveinung \newcommand\ltext[1]{\mbox{#1}}
\newcommand\term[1]{\emph{\mbox{#1}}}
\newcommand\acronym[1]{\ltext{#1}}
\newcommand\classname[1]{\mbox{\tt #1}}
\newcommand\propertykey[1]{\mbox{\tt #1}}
\newcommand\propertyvalue[1]{\mbox{\tt #1}}
\newcommand\methodname[1]{\mbox{\tt #1}}
\newcommand\filename[1]{\mbox{\sl #1}}
\newcommand\packagename[1]{\mbox{\tt\sl #1}}
\newcommand\xcallout[1]{\hfill\textcircled{#1}}
\newcommand\xkeyword[1]{{\bf #1}}
\newcounter{calloutindex}
\newenvironment{callout}%
{\begin{itemize}\setcounter{calloutindex}{1}}%
{\end{itemize}}
\newcommand\coitem{\item[\textcircled{\arabic{calloutindex}}%
\addtocounter{calloutindex}{1}]}
\newenvironment{example}%
{\par\vskip 6pt\tt\small\obeylines\obeyspaces}%
{\vskip 6pt}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/Makefile 0000644 0001750 0001750 00000001006 07616770720 025470 0 ustar sveinung sveinung MAIN=NanoXML-Lite
COMPONENTS=NanoXML-Lite.tex defs.tex introduction.tex retrieving_data.tex
PDFLATEX=/usr/local/teTeX/bin/powerpc-apple-darwin-current/pdflatex
all: $(MAIN).pdf
clean:
rm -f $(MAIN).pdf $(COMPONENTS:.tex=.aux) $(MAIN).log $(MAIN).toc
$(MAIN).pdf: $(COMPONENTS)
sed "s/ModDate (D:[0-9]*)/ModDate (D:`date +'%Y%m%d%H%M%S'`)/" \
< $(MAIN).tex >$(MAIN).tmp
mv $(MAIN).tmp $(MAIN).tex
$(PDFLATEX) $(MAIN).tex
$(PDFLATEX) $(MAIN).tex >/dev/null 2>&1
$(PDFLATEX) $(MAIN).tex >/dev/null 2>&1
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/ 0000755 0001750 0001750 00000000000 11045140126 023020 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/ 0000755 0001750 0001750 00000000000 11045140126 023775 5 ustar sveinung sveinung libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/introduction.tex 0000644 0001750 0001750 00000012317 07616770720 027266 0 ustar sveinung sveinung \chapter{Introduction}
This chapter gives a short introduction to \XML{} and \NanoXML{}.
\section{About \XML{}}
The extensible markup language,
\href{http://www.w3c.org/TR/REC-xml}{\XML{}}, is a way to mark up text in
a structured document.
\XML is a simplification of the complex \ltext{SGML} standard.
\ltext{SGML}, the Standard Generalized Markup Language, is an international
(\ltext{ISO}) standard for marking up text and graphics.
The best known application of \ltext{SGML} is \ltext{HTML}.
Although \ltext{SGML} data is very easy to write, it's very difficult to write a
generic \ltext{SGML} parser.
When designing \XML{} however, the authors removed much of the flexibility
of \ltext{SGML} making it much easier to parse \XML{} documents correctly.
\XML{} data is structured as a tree of \term{entities}.
An entity can be a string of character data or an element which can contain other
entities.
Elements can optionally have a set of attributes.
Attributes are key/value pairs which set some properties of an element.
The following example shows some \XML{} data:
\begin{example}
$<$book$>$
~~$<$chapter id="my chapter"$>$
~~~~$<$title$>$The title$<$/title$>$
~~~~Some text.
~~$<$/chapter$>$
$<$/book$>$
\end{example}
At the root of the tree, you can find the element ``book''.
This element contains one child element: ``chapter''.
The chapter element has one attribute which maps the key ``id'' to
``my chapter''.
The chapter element has two child entities: the element ``title'' and the
character data ``Some text.''.
Finally, the title element has one child, the string ``The title''.
\section{About \NanoXML{}}
In April 2000, \NanoXML{} was first released as a spin-off project of
\ltext{AUIT}, the Abstract User Interface Toolkit.
The intent of NanoXML was to be a small parser which was easy to use.
\ltext{SAX} and \ltext{DOM} are much too complex for what I needed and the
mainstream parsers were either much too big or had a very restrictive license.
\ltext{NanoXML 1} has all the features I needed: it is very small (about 6K),
is reasonably fast for small \XML{} documents, is very easy to use and is
free (\ltext{zlib/libpng} license).
As I never intended to use \NanoXML{} to parse \ltext{DocBook} documents,
there was no support for mixed data or \ltext{DTD} parsing.
\NanoXML{} was released as a \ltext{SourceForge} project and, because of the
very good response from its users, it matured to a small and stable parser.
The final version, release \ltext{1.6.8} was released in May 2001.
Because of its small size, people started to use \NanoXML{} for embedded
systems (\ltext{KVM}, \ltext{J2ME}) and kindly submitted patches to make
\NanoXML{} work in such restricted environment.
\section{\NanoXML{} 2}
In July 2001, \ltext{NanoXML 2} has been released.
Unlike \ltext{NanoXML 1}, speed and \XML{} compliancy were considered to be
very important when the new parser was designed.
\ltext{NanoXML 2} is also very modular: you can easily replace the different
components in the parser to customize it to your needs.
The modularity of \ltext{NanoXML 2} also benefits extensions like \acronym{e.g.} \ltext{SAX} support which can now directly access the parser.
In \ltext{NanoXML 1}, the \ltext{SAX} adapter had to iterate the data structure built by the base product.
Although many features were added to \NanoXML{}, the second release was
still very small.
The full parser with builder fits in a \ltext{JAR} file of about 32K.
This is still very tiny, especially when you compare this with the ``standard'' parsers of more than four times its size.
As there is still need for a tiny parser like \ltext{NanoXML 1}, there is a
special branch of \ltext{NanoXML 2}: \ltext{NanoXML/Lite}. This parser is source compatible with \ltext{NanoXML 1} but features a new parsing algorithm which makes it more than twice as fast as the older version.
It is however more restrictive on the \XML{} data it parses: the older
version allowed some not-wellformed data to be parsed.
There are three branches of \ltext{NanoXML 2}:
\begin{itemize}
\item[$\bullet$]
\term{NanoXML/Lite} is the successor of \ltext{NanoXML 1}.
It features an almost compatible parser which is extremely small.
\item[$\bullet$]
\term{NanoXML/Java} is the standard parser.
\item[$\bullet$]
\term{NanoXML/SAX} is the \ltext{SAX} adapter for \ltext{NanoXML/Java}.
\end{itemize}
The latest version of \NanoXML{} is \ltext{NanoXML 2.2.1}, which has been
released in April 2002.
\section{\NanoXML{} Extension to the \XML{} System ID}
Because it's convenient to put data files into jar files, we need some way to specify that we want some resource which can be found in the class path.
There is no support for such resources in the \XML{} 1.0 specification.
NanoXML allows you to specify such resources using the
\emph{reference part} of a \ltext{URL}.
This means that if the \ltext{DTD} of the \XML{} data is put in the
resource \filename{/data/foo.dtd}, you can specify such path using the
following document type declaration:
\begin{example}
$<$!DOCTYPE foo SYSTEM 'file:\#/data/foo.dtd'$>$
\end{example}
It's even possible to specify a resource found in a particular jar, like in the following example:
\begin{example}
$<$!DOCTYPE foo SYSTEM 'http://myserver.com/dtds.jar\#/foo.dtd'$>$
\end{example}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/streaming_data.tex 0000644 0001750 0001750 00000010555 07616770720 027531 0 ustar sveinung sveinung \chapter{Retrieving Data From An \XML{} Stream}
If you're retrieving data from a stream, but you don't want to wait to process the data until it's completely read, you can use streaming.
\section{The \XML{} Builder}
The \XML{} data tree is created using an \XML{} builder. By default, the builder creates a tree of \classname{IXMLElement}.
While the parser parses the data, it notifies the builder of any elements it encounters. Using this information, the builder generate the object tree. When the parser is done processing the data, it retrieves the object tree from the builder using \methodname{getResult}.
The following example shows a simple builder that prints the notifications on the standard output.
\begin{example}
\xkeyword{import} java.io.*;
\xkeyword{import} net.n3.nanoxml.*;
~
\xkeyword{public class} MyBuilder
~~~~\xkeyword{implements} IXMLBuilder
~~\{
~~\xkeyword{public void} startBuilding(String systemID,\xcallout{1}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr)
~~\{
~~~~System.out.println("Document started");
~~\}
~
~~\xkeyword{public void} newProcessingInstruction(String target,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Reader reader)
~~~~\xkeyword{throws} IOException
~~\{
~~~~System.out.println("New PI with target " + target);
~~\}
~
~~\xkeyword{public void} startElement(String name,\xcallout{3}
~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix,
~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID,
~~~~~~~~~~~~~~~~~~~~~~~~~~~String systemID,
~~~~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr)
~~\{
~~~~System.out.println("Element started: " + name);
~~\}
~
~~\xkeyword{public void} endElement(String name,\xcallout{4}
~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix,
~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID)
~~\{
~~~~System.out.println("Element ended: " + name);
~~\}
~
~~\xkeyword{public void} addAttribute(String key,\xcallout{5}
~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix,
~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID,
~~~~~~~~~~~~~~~~~~~~~~~~~~~String value,
~~~~~~~~~~~~~~~~~~~~~~~~~~~String type)
~~\{
~~~~System.out.println(" " + key + ": " + type + " = " + value);
~~\}
~
~~\xkeyword{public void} elementAttributesProcessed(String name,\xcallout{6}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID)
~~\{
~~~~// nothing to do
~~\}
~
~~\xkeyword{public void} addPCData(Reader reader,\xcallout{7}
~~~~~~~~~~~~~~~~~~~~~~~~String systemID,
~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr)
~~~~\xkeyword{throws} IOException
~~\{
~~~~System.out.println("\#PCDATA");
~~\}
~
~~\xkeyword{public} Object getResult()\xcallout{8}
~~\{
~~~~\xkeyword{return null};
~~\}
\}
\end{example}
\begin{callout}
\coitem
The \XML{} parser started parsing the document. The \variable{lineNr}
parameter contains the line number where the document starts.
\coitem
The \XML{} parser encountered a processing instruction (PI) which is not
handled by the parser itself.
The target contains the target of the PI.
The contents of the PI can be read from reader.
\coitem
A new element has been started at line \variable{lineNr}.
The name of the element is stored in \variable{name}.
\coitem
The current element has ended.
For convenience, the name of that element is put in the parameter
\variable{name}.
\coitem
An attribute is added to the current element.
\coitem
This method is called when all the attributes of the current element
have been processed.
\coitem
A \ltext{\#PCDATA} section has been encountered.
The contents of the section can be read from reader.
\coitem
This method is called when the parsing has finished.
If the builder has a result, it has to return it to the parser in this
method.
\end{callout}
\section{Registering an XML Builder}
You can register the builder to the parser using the method \methodname{setBuilder}.
The following example shows how to create a parser which uses the builder we created in the previous section:
\begin{example}
\xkeyword{import} net.n3.nanoxml.*;
\xkeyword{import} java.io.*;
~
\xkeyword{public class} DumpXML
\{
~~\xkeyword{public static void} main(String args[])
~~~~\xkeyword{throws} Exception
~~\{
~~~~IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
~~~~IXMLReader reader = StdXMLReader.fileReader("test.xml");
~~~~parser.setReader(reader);
~~~~parser.setBuilder(new MyBuilder());
~~~~parser.parse();
~~\}
\}
\end{example}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/retrieving_data.tex 0000644 0001750 0001750 00000024461 07616770720 027717 0 ustar sveinung sveinung \chapter{Retrieving Data From An \XML{} Datasource}
This chapter shows how to retrieve \XML{} data from a standard data
source.
Such source can be a file, an \ltext{HTTP} object or a text string.
The method described in this chapter is the simplest way to retrieve
\XML{} data.
More advanced ways are described in the next chapters.
\section{A Very Simple Example}
This section describes a very simple \XML{} application.
It parses \XML{} data from a stream and dumps it ``pretty-printed'' to
the standard output.
While its use is very limited, it shows how to set up a parser and parse an
\XML{} document.
\begin{example}
\xkeyword{import} net.n3.nanoxml.*;\xcallout{1}
\xkeyword{import} java.io.*;
\xkeyword{public class} DumpXML
\{
~~\xkeyword{public static void} main(String[] args)
~~~~\xkeyword{throws} Exception
~~\{
~~~~IXMLParser parser = XMLParserFactory.createDefaultXMLParser();\xcallout{2}
~~~~IXMLReader reader = StdXMLReader.fileReader("test.xml");\xcallout{3}
~~~~parser.setReader(reader);
~~~~IXMLElement xml = (IXMLElement) parser.parse();\xcallout{4}
~~~~XMLWriter writer = new XMLWriter(System.out);\xcallout{5}
~~~~writer.write(xml);
~~\}
\}
\end{example}
\begin{callout}
\coitem
The \NanoXML{} classes are located in the package
\packagename{net.n3.nanoxml}.
\coitem
This command creates an \XML{} parser.
The actual class of the parser is dependent on the value of the system
property \propertykey{net.n3.nanoxml.XMLParser}, which is by default
\propertyvalue{net.n3.nanoxml.StdXMLParser}.
\coitem
The command creates a ``standard'' reader which reads its data from the
file called \filename{test.xml}.
Usually you can use \classname{StdXMLReader} to feed the \XML{} data to
the parser.
The default reader is able to set up HTTP connections when retrieving
\ltext{DTDs} or entities from different machines.
If necessary, you can supply your own reader to \acronym{e.g.} provide
support for \ltext{PUBLIC} identifiers.
\coitem
The \XML{} parser now parses the data read from \filename{test.xml}
and creates a tree of parsed \XML{} elements.
The structure of those elements will be described in the next section.
\coitem
An \classname{XMLWriter} can be used to dump a ``pretty-printed'' view
of the parsed \XML data on an output stream.
In this case, we dump the read data to the standard output
\ltext{(System.out)}.
\end{callout}
\section{Analyzing The Data}
You can easily traverse the logical tree generated by the parser.
If you need to create your own object tree, you can create your custom
% TODO: make "chapter 3" a xref
builder, which is described in chapter 3.
The default \XML{} builder, \classname{StdXMLBuilder} generates a tree of
\classname{IXMLElement} objects.
Every such object has a name and can have attributes, \ltext{\#PCDATA} content and child objects.
The following XML data:
\begin{example}
$<$FOO attr1="fred" attr2="barney"$>$
~~~~$<$BAR a1="flintstone" a2="rubble"$>$
~~~~~~~~Some data.
~~~~$<$/BAR$>$
~~~~$<$QUUX/$>$
$<$/FOO$>$
\end{example}
is parsed to the following objects:
\begin{itemize}
\item[] Element FOO:
\begin{itemize}
\item[] Attributes = \{ "attr1"="fred", "attr2"="barney" \}
\item[] Children = \{ BAR, QUUX \}
\item[] PCData = null
\end{itemize}
\item[] Element BAR:
\begin{itemize}
\item[] Attributes = \{ "a1"="flintstone", "a2"="rubble" \}
\item[] Children = \{\}
\item[] PCData = "Some data."
\end{itemize}
\item[] Element QUUX:
\begin{itemize}
\item[] Attributes = \{\}
\item[] Children = \{\}
\item[] PCData = null
\end{itemize}
\end{itemize}
You can retrieve the name of an element using \methodname{getFullName}, thus:
\begin{example}
FOO.getFullName() $\to$ "FOO"
\end{example}
You can enumerate the attribute keys using
\methodname{enumerateAttributeNames}:
\begin{example}
Enumeration enum = FOO.enumerateAttributeNames();
\xkeyword{while} (enum.hasMoreElements()) \{
~~System.out.print(enum.nextElement());
~~System.out.print(' ');
\}
$\to$ attr1 attr2
\end{example}
You can retrieve the value of an attribute using \methodname{getAttribute}:
\begin{example}
FOO.getAttribute ("attr1", null) $\to$ "fred"
\end{example}
The child elements can be enumerated using \methodname{enumerateChildren}:
\begin{example}
Enumeration enum = FOO.enumerateChildren();
\xkeyword{while} (enum.hasMoreElements()) \{
~~System.out.print(enum.nextElement() + ' ');
\}
$\to$ BAR QUUX
\end{example}
If the element contains parsed character data \ltext{(\#PCDATA)} as its only
child.
You can retrieve that data using \methodname{getContent}:
\begin{example}
BAR.getContent() $\to$ "Some data."
\end{example}
If an element contains both \ltext{\#PCDATA} and \XML elements as its
children, the character data segments will be put in untitled \XML
elements (whose name is \ltext{null}).
\classname{IXMLElement} contains many convenience methods for retrieving data
and traversing the \XML tree.
\section{Generating \XML}
You can very easily create a tree of \XML elements or modify an
existing one.
To create a new tree, just create an \classname{IXMLElement} object:
\begin{example}
IXMLElement elt = \xkeyword{new} XMLElement("ElementName");
\end{example}
You can add an attribute to the element by calling \methodname{setAttribute}.
\begin{example}
elt.setAttribute("key", "value");
\end{example}
You can add a child element to an element by calling \methodname{addChild}:
\begin{example}
IXMLElement child = elt.createElement("Child");
elt.addChild(child);
\end{example}
Note that the child element is created calling \methodname{createElement}.
This insures that the child instance is compatible with its new parent.
If an element has no children, you can add \ltext{\#PCDATA} content to it using
\methodname{setContent}:
\begin{example}
child.setContent("Some content");
\end{example}
If the element does have children, you can add \ltext{\#PCDATA} content to it
by adding an untitled element, which you create by calling
\methodname{createPCDataElement}:
\begin{example}
IXMLElement pcdata = elt.createPCDataElement();
pcdata.setContent("Blah blah");
elt.addChild(pcdata);
\end{example}
When you have created or edited the XML element tree, you can write it out to
an output stream or writer using an \classname{XMLWriter}:
\begin{example}
java.io.Writer output = \ldots;
IXMLElement xmltree = \ldots;
XMLWriter xmlwriter = new XMLWriter(output);
writer.write(xmltree);
\end{example}
\section{Namespaces}
As of version 2.1, \ltext{NanoXML} has support for namespaces.
Namespaces allow you to attach a \ltext{URI} to the name of an element name or an attribute.
This \ltext{URI} allows you to make a distinction between similary named
entities coming from different sources.
More information about namespaces can be found in the XML Namespaces
recommendation, which can be found at
\href{http://www.w3c.org/TR/REC-xml-names/}%
{http://www.w3c.org/TR/REC-xml-names/}.
Please note that a \ltext{DTD} has no support for namespaces.
It is important to understand that an \XML document can have only one
\ltext{DTD}.
Though the namespace \ltext{URI} is often presented as a \ltext{URL}, that
\ltext{URL} is not a system id for a \ltext{DTD}.
The only function of a namespace \ltext{URI} is to provide a globally unique
name.
As an example, letŐs have the following \XML data:
\begin{example}
$<$doc:book xmlns:doc="http://nanoxml.n3.net/book"$>$
~~$<$chapter xmlns="http://nanoxml.n3.net/chapter"
~~~~~~~~~~~title="Introduction"
~~~~~~~~~~~doc:id="chapter1"/$>$
$<$/doc:book$>$
\end{example}
The top-level element uses the namespace \ltext{``http://nanoxml.n3.net/book''}.
The prefix is used as an alias for the namespace, which is defined in the
attribute \ltext{xmlns:doc}.
This prefix is defined for the \ltext{doc:book} element and its child elements.
The chapter element uses the namespace
\ltext{``http://nanoxml.n3.net/chapter''}.
Because the namespace \ltext{URI} has been defined as the value of the xmlns
attribute, the namespace is the default namespace for the chapter element.
Default namespaces are inherited by the child elements, but only for their
names.
Attributes never have a default namespace.
The chapter element has an attribute \ltext{doc:id}, which is defined in the
same namespace as \ltext{doc:book} because of the doc prefix.
\ltext{NanoXML 2.1} offers some variants on the standard retrieval methods to allow the application to access the namespace information.
In the following examples, we assume the variable book to contain the
\ltext{doc:book} element and the variable chapter to contain the chapter
element.
To get the full name, which includes the namespace prefix, of the element, use \methodname{getFullName}:
\begin{example}
book.getFullName() $\to$ "doc:book"
chapter.getFullName() $\to$ "chapter"
\end{example}
To get the short name, which excludes the namespace prefix, of the element,
use \methodname{getName}:
\begin{example}
book.getName() $\to$ "book"
chapter.getName $\to$ "chapter"
\end{example}
For elements that have no associated namespace, \methodname{getName} and
\methodname{getFullName} are equivalent.
To get the namespace \ltext{URI} associated with the name of the element, use \methodname{getNamespace}:
\begin{example}
book.getNamespace() $\to$ "http://nanoxml.n3.net/book"
chapter.getNamespace() $\to$ "http://nanoxml.n3.net/chapter"
\end{example}
If no namespace is associated with the name of the element, this method returns \variable{null}.
You can get an attribute of an element using either its full name (which
includes its prefix) or its short name together with its namespace \ltext{URI}, so the following two instructions are equivalent:
\begin{example}
chapter.getAttribute("doc:id", null)
chapter.getAttribute("id", "http://nanoxml.n3.net/book", null)
\end{example}
Note that the title attribute of chapter has no namespace, even though the
chapter element name has a default namespace.
You can create a new element which uses a namespace this way:
\begin{example}
book = \xkeyword{new} XMLElement("doc:book", "http://nanoxml.n3.net/book");
chapter = book.createElement("chapter",
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"http://nanoxml.n3.net/chapter");
\end{example}
You can add an attribute which uses a namespace this way:
\begin{example}
chapter.setAttribute("doc:id",
~~~~~~~~~~~~~~~~~~~~~"http://nanoxml.n3.net/book",
~~~~~~~~~~~~~~~~~~~~~chapterId);
\end{example}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/NanoXML-Java.tex 0000644 0001750 0001750 00000001173 07616770720 026676 0 ustar sveinung sveinung \documentclass[a4paper]{book}
\usepackage[pdftex]{graphicx}
\usepackage{hyperref}
\DeclareGraphicsExtensions{.pdf}
\title{NanoXML/Java 2.2}
\author{Marc De Scheemaecker $<$cyberelf@mac.com$>$}
\pdfinfo {
/Title (NanoXML/Java 2.2)
/Creator (LaTeX)
/Producer (pdfTeX 0.14a)
/Author (Marc De Scheemaecker)
/CreationDate (D:20020205000000)
/ModDate (D:20030201171151)
/Subject (NanoXML/Java)
/Keywords (NanoXML,XML)
}
\include{defs}
\begin{document}
\titlepage
\maketitle
\tableofcontents
\include{introduction}
\include{retrieving_data}
\include{streaming_data}
\include{advanced}
\end{document}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/defs.tex 0000644 0001750 0001750 00000001514 07616770720 025463 0 ustar sveinung sveinung \newcommand\ltext[1]{\mbox{#1}}
\newcommand\XML{\ltext{XML}}
\newcommand\NanoXML{\ltext{NanoXML}}
\newcommand\term[1]{\emph{\mbox{#1}}}
\newcommand\acronym[1]{\ltext{#1}}
\newcommand\classname[1]{\mbox{\tt #1}}
\newcommand\variable[1]{\mbox{\tt #1}}
\newcommand\propertykey[1]{\mbox{\tt #1}}
\newcommand\propertyvalue[1]{\mbox{\tt #1}}
\newcommand\methodname[1]{\mbox{\tt #1}}
\newcommand\filename[1]{\mbox{\sl #1}}
\newcommand\packagename[1]{\mbox{\tt\sl #1}}
\newcommand\xcallout[1]{\hfill\textcircled{#1}}
\newcommand\xkeyword[1]{{\bf #1}}
\newcounter{calloutindex}
\newenvironment{callout}%
{\begin{itemize}\setcounter{calloutindex}{1}}%
{\end{itemize}}
\newcommand\coitem{\item[\textcircled{\arabic{calloutindex}}%
\addtocounter{calloutindex}{1}]}
\newenvironment{example}%
{\par\vskip 6pt\tt\small\obeylines\obeyspaces}%
{\vskip 6pt}
libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/structure.graffle 0000744 0001750 0001750 00000043307 07616770720 027417 0 ustar sveinung sveinung