Hi,
I need to parse an xml document (xml file) using SAX API.
A portion of the .xml file looks as follows (for displaying 1 row of
information).
<case id="RMA-1234">
<assigned-to>Abrao I. Grynglas</assigned-to>
<subject>This is the subject of email</subject>
<referred-to>Yes</referred-to>
<status>Document Open</status>
<date>16-Sep-03</date>
<priority>High</priority>
</case>
I use the following java source code to do the same.
*************************************
class MyHandler extends DefaultHandler
{
private Set Cases = new TreeSet();
private String strCase = "";
public MyHandler(){}
public void startElement(String namespaceURI,String localname,String
rawname,Attributes atts) throws SAXException
{
if (localname.equals("case"))
{
for (int i = 0; i < atts.getLength(); i++)
{
String attName = atts.getLocalName(i);
if (attName.equals("id"))
strCase = atts.getValue(i);
}
}
}
public void endElement(String namespaceURI,String localname,String
rawname) throws SAXException
{
if (localname.equals("case"))
{
String thisCase = strCase.toString().trim();
Cases.add(thisCase);
}
}
public void characters(char [] buf,int offset,int len){
String partOfCaseName = new String(buf, offset, len);
}
public Set getCases(){
return Cases;
}
}
*************************************
So the above code returns only the attribute values from the first main element
"case". I would also like to retrieve (using SAX) the values of simple elements
also. Can anyone guide me how to achieve this, please ?
Thanks and Regards
S Srikanth
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]