Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - unable to preserve whitespace

 
Thread Tools Search this Thread
Old 05-18-2006, 09:03 PM   #1
Default unable to preserve whitespace


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



soup_or_power@yahoo.com
  Reply With Quote
Old 05-19-2006, 03:02 AM   #2
Joe Kesselman
 
Posts: n/a
Default Re: unable to preserve whitespace

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.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump