SAXParser

using SAX parser can i get value only for status.EmploymentStatus.StatusDesc ? below is my xml.

<Status>

<EmploymentStatus>

<StatusDesc>Active</StatusDesc>

<StartDt>19530618</StartDt>

</EmploymentStatus>

<TaxStatus>

<StatusDesc>Independent Contractor</StatusDesc>

<StartDt>19540617</StartDt>

</TaxStatus>

<Position>

<PositionCd>000051</PositionCd>

<StartDt>20000322</StartDt>

<StatusDesc>IC FINANCIAL ADVISOR</StatusDesc>

</Position>

<FACTSRole>

<FACTSRoleCd>40</FACTSRoleCd>

<StatusDesc>Fas Qualified</StatusDesc>

</FACTSRole>

</Status>

[853 byte] By [chintan.inda] at [2007-10-2 21:34:54]
# 1

Basically, SAXParser will handle data extraction for all nodes. As I answered in your previous post about using arraylist, I'll handle it like this.

public void endElement(String namespaceURI, String sName, String qName) throws SAXException {

if (needData) { // needData is a boolean

if (chkNodes(qName)) { // check if the node is in the arraylist

needData = true; // if yes, then you continue to get the data

}

else

needData = false; // if no, just skip it

}

}

public boolean chkNodes(String qName) {

for(int i=0; i<arrayList.size(); i++) {

if (qName.equals(arrayList.get(i)))

return true;

}

return false;

}

>

TikkyChaia at 2007-7-14 0:48:49 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Can u help on same,I have already a XML file, in this i want to replace the element value please guide me Prasanna
PrasannA@javaa at 2007-7-14 0:48:49 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Hi

I guess you are better off using DOM + Xpath rather than SAX...The following sample using JAXP in JDK 5.0

Here is an example of how u can do this..

System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setNamespaceAware(true);

DocumentBuilder builder = factory.newDocumentBuilder();

Document dom = builder.parse("D:\\Development\\eibus\\mntc\\study\\xml\\xpath\\inputp.xml");

XPathFactory xfactory = XPathFactory.newInstance();

XPath xpath = xfactory.newXPath();

Node content = (Node)xpath.evaluate("//Acknowledgement//UUId", dom, XPathConstants.NODE);

System.out.println(((Element)content).getTextContent());

((Element)content).setTextContent("newvalue");

System.out.println(((Element)content).getTextContent());

senthilkumar_ksa at 2007-7-14 0:48:49 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
thanks for ur help, I changed to DOM - It's working finenow I have the XML - that I want to send to JMSI got the code how to do it, but I don't know how to do the settings in Weblogic for JNDI connection.please guide me..........Prasanna
PrasannA@javaa at 2007-7-14 0:48:49 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...