Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use IBM's XML4J for testing files

 
clyde mel
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I use the IBM's XML4J for testing the files below.I also have the jaxp and the jdk 1.3 version.

xml file : (saxxml.xml file)
<?xml version="1.0"?>
<players>
����
<player> ������
��<name>Sanjay</name> ������
��<form>Batsman</form> �������
� <NrOfMatches>1</NrOfMatches> �
���</player>
���
�<player> ��������
<name>Kapil</name> �����
�<form>Bowler</form> ����
�<NrOfMatches>3</NrOfMatches> �
�</player>
����
<player> �������
�<name>Purvesh</name> ��������
<form>All rounder</form> ������
�<NrOfMatches>2</NrOfMatches> ��
�</player> �
���
<player> �������
�<name>Pradeep</name> �������
�<form>All rounder</form> ���
�<NrOfMatches>1</NrOfMatches> ���
�</player>
</players>

.java file
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Attributes;
import java.io.*;
public class Processor extends DefaultHandler {
��private PrintWriter fout; ��
�public Processor() throws IOException ��
��{ ��������
fout = new PrintWriter(new FileWriter("HTMLOutput.htm"));
��} ���
�public void startDocument() ����
{ �����
���fout.println("<HTML>"); ���fout.println("<HEAD><TITLE>SAX example</TITLE></HEAD>"); ���fout.println("<BODY>"); ���
} ���
�public void endDocument()
����{ �������
�fout.println("</BODY></HTML>"); ����
����fout.close(); ����
} ����
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) ���
�{ ����
����if (localName.equals("players")) ������������fout.println("<TABLE BORDER = '1' CELLPADDING = '5'>"); ��������else if (localName.equals("player")) ��������������{ ������������������fout.println("<TR>"); ������������
��} �������������
�else ���������
�����{ ����������������
��fout.println("<TD>"); ������������
��} ���
�} ���
�public void endElement(String namespaceURI, String localName, String qName) ���
�{ �������
�if (localName.equals("players")) ���������fout.println("</TABLE>");
��������else if (localName.equals("player")) �������������
���{ �������������������
�fout.println("</TR>"); �����������
�����} ����������������
else �������������
���{ ����������
����������fout.println("</TD>"); ������������
����} ��
�} ��
��public void characters (char ch[], int start, int length)
����{ �������
�for (int i = start; i < start+length; i++) ������������fout.println(ch[i]); ��
��}
}

Conversion .java file :
import org.xml.sax.Parser;
import org.xml.sax.DocumentHandler;
import org.xml.sax.helpers.ParserFactory;
import java.io.File;
public class convert
{
���static final String parserClass = "com.ibm.xml.parsers.SAXDriver";
����// using IBM’s XML parser ���
�static final String xmlfile = "saxxml.xml";
��public static void main (String args[]) throws Exception �
�� { ����
���Parser parser; ���
���DocumentHandler handler; ���
���parser = ParserFactory.makeParser(parserClass); ���handler = new Processor(); ���parser.setDocumentHandler(handler); ���parser.parse(xmlfile); ��
�� }
}
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh i thought IBM donated XML4j to apache and it has evolved into xerces! Anyway are people still usign xml4j? I thought xerces is the most popular parser. If you intend to use xerces, this s'd work.. + it is JAXP compliant

No idea of xml4j though.
HTH
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic