unable to preserve whitespace

S

soup_or_power

I am unable to preserve white space.

Here is my code:
public class xml {
public static void main(String[] args) {
try{
String jaxpPropertyName = "javax.xml.parsers.SAXParserFactory";
if (System.getProperty(jaxpPropertyName) == null) {
String apacheXercesPropertyValue =
"org.apache.xerces.jaxp.SAXParserFactoryImpl";
System.setProperty(jaxpPropertyName,
apacheXercesPropertyValue);
}
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
Reader reader=new StringReader("<?xml version='1.0'
encoding='UTF-8'?><References><Reference><Name>RITA
MOYER</Name><Address><Street>5001 OAKVIEW DRIVE </Street><City>Los
Angeles</City><State>OH</State><ZIP>44089</ZIP></Address><EMail></EMail><Phone>4409678038</Phone><Relationship>MOTHER</Relationship></Reference><Reference><Name>TINA
MASLINSKI</Name><Address><Street>4902 MAPLE VIEW
DRIVE</Street><City>Los
Angeles</City><State>OH</State><ZIP>44089</ZIP></Address><EMail></EMail><Phone>4409675992</Phone><Relationship>FRIEND</Relationship></Reference></References>");
InputSource is=new InputSource(reader);
factory.setNamespaceAware(true);
parser.parse(is, new PrintHandler());
} catch(Exception e) {
e.printStackTrace();
}
}
}

I want the parser to show for Name "Rita Moyer". It now shows "Rita"

Thanks for your help
 
J

Joe Kesselman

I strongly suspect PrintHandler (which you didn't show us) has the
standard SAX-beginner's problem of forgetting that text may be spread
over successive calls to characters(). See any good SAX tutorial for a
discussion of how to deal with that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top