Implementing a custom XMLReader

Hi,Can someone point me to a good starting page for creating acustom XMLReader?
[100 byte] By [Puzza] at [2007-11-26 13:15:13]
# 1

try this,

import java.util.*;

import org.w3c.dom.*;

import org.xml.sax.SAXException;

import java.io.StringReader;

import oracle.xml.parser.v2.*;

public static NodeList parseXml (String s) {

DOMParser d = new DOMParser();

try {

d.parse( new StringReader(s) );

return ((XMLDocument)d.getDocument()).selectNodes("/");

} catch (Exception e) {

return (new XMLDocument()).getChildNodes();

}

}

Selvaganapathya at 2007-7-7 17:35:44 > top of Java-index,Java Essentials,Java Programming...
# 2
Here's an example of an [url= http://www.xml.com/lpt/a/1247]XML Fragment Reader[/url].
karma-9a at 2007-7-7 17:35:44 > top of Java-index,Java Essentials,Java Programming...
# 3

here is a simple xml reader

import javax.xml.parsers.SAXParserFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.parsers.SAXParser;

import org.xml.sax.helpers.DefaultHandler;

import org.xml.sax.SAXParseException;

import org.xml.sax.SAXException;

import org.xml.sax.Attributes;

import java.io.File;

import java.util.Vector;

class XMLParser extends DefaultHandler{

String tag = null;

String[] attributes = null;

Vector data = null;

public XMLParser(String tag, String[] attributes) {

this.tag = tag;

this.attributes = attributes;

data = new Vector();

}

public void fatalError (SAXParseException e){

}

public void error (SAXParseException e){

}

public void warning (SAXParseException e){

}

public void startDocument(){

}

public void endDocument(){

}

public void startElement(String s_name, String localName, String qName, Attributes attrs){

if (qName.equals(tag)) {

if (attrs != null) {

String [] tmpArr = null;

for (int i = 0; i < attrs.getLength(); i++) {

String aName = attrs.getLocalName(i);

if ("".equals(aName)) aName = attrs.getQName(i);

for (int j = 0; j < attributes.length; j ++) {

if (attributes[j].equals(aName)) {

if (tmpArr == null) tmpArr = new String[attributes.length];

How to call it :

String[] attributes = {"NAME", "TYPE", "CLASS", "METHOD", "SAVE", "UPDATE"};

String tag = "PREFERENCE";

XMLParser xmlParser = new XMLParser(tag, attributes);

String filename = "test.xml";Vector v = xmlParser.read_my_document(new File(filename));

And a simple XML file :

<PREFERENCES>

<PREFERENCE NAME="Java Globus Desktop" TYPE="M" CLASS="JGlobus" METHOD="getJGDPreferences" SAVE="" UPDATE=""/>

<PREFERENCE NAME="PVCS"CLASS="JGlobus" TYPE="M" METHOD="getPVCSPreferences" SAVE="savePVCSPreferences" UPDATE="updatePVCSPreferences"/>

<PREFERENCE NAME="Patch detail"CLASS="JPatchDetail" TYPE="A" METHOD="getPreferences" SAVE="savePreferences" UPDATE="updatePreferences"/>

<PREFERENCE NAME="PVCS labels compare" CLASS="JCompare" TYPE="A" METHOD="getPreferences" SAVE="savePreferences" UPDATE="updatePreferences"/>

</PREFERENCES>

The vector as result contains arrays of values for each tag

ProZa at 2007-7-7 17:35:44 > top of Java-index,Java Essentials,Java Programming...