[ Pobierz całość w formacie PDF ]

SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter(System.out, "UTF8");
// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(argv[0]), handler);
} catch (Throwable t) {
t.printStackTrace();
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04.java (1 of 4) [8/22/2001 12:53:36 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04.java
}
System.exit(0);
}
static private Writer out;
private String indentString = " "; // Amount to indent
private int indentLevel = 0;
//===========================================================
// SAX DocumentHandler methods
//===========================================================
public void setDocumentLocator(Locator l)
{
// Save this to resolve relative URIs or to give diagnostics.
try {
out.write("LOCATOR");
out.write("\n SYS ID: " + l.getSystemId() );
out.flush();
} catch (IOException e) {
// Ignore errors
}
}
public void startDocument()
throws SAXException
{
nl();
nl();
emit("START DOCUMENT");
nl();
emit("");
}
public void endDocument()
throws SAXException
{
nl(); emit("END DOCUMENT");
try {
nl();
out.flush();
} catch (IOException e) {
throw new SAXException("I/O error", e);
}
}
public void startElement(String namespaceURI,
String lName, // local name
String qName, // qualified name
Attributes attrs)
throws SAXException
{
indentLevel++;
nl(); emit("ELEMENT: ");
String eName = lName; // element name
if ("".equals(eName)) eName = qName; // namespaceAware = false
emit("
if (attrs != null) {
for (int i = 0; i
String aName = attrs.getLocalName(i); // Attr name
if ("".equals(aName)) aName = attrs.getQName(i);
nl();
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04.java (2 of 4) [8/22/2001 12:53:36 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04.java
emit(" ATTR: ");
emit(aName);
emit("\t\"");
emit(attrs.getValue(i));
emit("\"");
}
}
if (attrs.getLength() > 0) nl();
emit(">");
}
public void endElement(String namespaceURI,
String sName, // simple name
String qName // qualified name
)
throws SAXException
{
nl();
emit("END_ELM: ");
emit("");
indentLevel--;
}
public void characters(char buf[], int offset, int len)
throws SAXException
{
nl(); emit("CHARS: ");
String s = new String(buf, offset, len);
if (!s.trim().equals("")) emit(s);
}
//===========================================================
// Utility Methods ...
//===========================================================
// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void emit(String s)
throws SAXException
{
try {
out.write(s);
out.flush();
} catch (IOException e) {
throw new SAXException("I/O error", e);
}
}
// Start a new line
// and indent the next line appropriately
private void nl()
throws SAXException
{
String lineEnd = System.getProperty("line.separator");
try {
out.write(lineEnd);
for (int i=0; i
} catch (IOException e) {
throw new SAXException("I/O error", e);
}
}
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04.java (3 of 4) [8/22/2001 12:53:36 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04.java
}
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04.java (4 of 4) [8/22/2001 12:53:36 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04-01.html
Running Echo04 ../samples/slideSample01.xml
LOCATOR
SYS ID: file:/java/pubs/dev/xml/docs/tutorial/sax/work/../samples/slideSample01.xml
START DOCUMENT
ELEMENT:
ATTR: title "Sample Slide Show"
ATTR: date "Date of publication"
ATTR: author "Yours Truly"
>
CHARS:
CHARS:
ELEMENT:
ATTR: type "all"
>
CHARS:
ELEMENT:
CHARS: Wake up to WonderWidgets!
END_ELM:
CHARS:
END_ELM:
CHARS:
CHARS:
ELEMENT:
ATTR: type "all"
>
CHARS:
ELEMENT:
CHARS: Overview
END_ELM:
CHARS:
ELEMENT:
CHARS: Why
ELEMENT:
CHARS: WonderWidgets
END_ELM:
CHARS: are great
END_ELM:
CHARS:
ELEMENT:
END_ELM:
CHARS:
ELEMENT:
CHARS: Who
ELEMENT:
CHARS: buys
END_ELM:
CHARS: WonderWidgets
END_ELM:
CHARS:
END_ELM:
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04-01.html (1 of 2) [8/22/2001 12:53:37 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04-01.html
CHARS:
END_ELM:
END DOCUMENT
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo04-01.html (2 of 2) [8/22/2001 12:53:37 PM]
Wake up to WonderWidgets!
Why WonderWidgets are great Who buys WonderWidgets
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/samples/slideSample02.xml [8/22/2001 12:53:38 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/samples/slideSample02-xml.html
title="Sample Slide Show"
date="Date of publication"
author="Yours Truly"
>
Wake up to WonderWidgets!
Overview
Why WonderWidgets are great
Who buys WonderWidgets
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/samples/slideSample02-xml.html [8/22/2001 12:53:39 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/work/Echo05.java
/*
* @(#)Echo05.java 1.5 99/02/09
*
* Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • rafalstec.xlx.pl