[jdom-interest] White space........while parsing XML

Naveen My perlnaveen at yahoo.com
Tue Jul 8 10:58:52 PDT 2003


When I run the below program..I get
 
org.jdom.input.JDOMParseException: Error on line 1: White space is required between the processing instruction target and data.
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:381)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:764)
        at parseXML.process(parseXML.java:25)
        at parseXML.main(parseXML.java:58)
Caused by: org.xml.sax.SAXParseException: White space is required between the processing i
nstruction target and data.
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
 
 
 
 
 
 
import java.io.*;
import java.net.URL;
import java.util.List;
import java.util.Iterator;
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
/**
* This class reads a xml formatted string and parse it
* get a root element, its children and children's attribute.
*/
public class parseXML 
{
 // Download and Process XML File
 public void process (String myXMLString)
 {
  try 
  {
   // Use SAXBuilder
   SAXBuilder builder = new SAXBuilder();
   Document doc = builder.build(new StringReader(myXMLString));
   extractElements(doc);
  } 
  catch (Exception e) 
  {
   e.printStackTrace();
  }
 }
 // Walk through JDOM Tree and extract all articles
 // For each article, print article ID, headline text and source
 private void extractElements(Document doc) 
 {
  Element root = doc.getRootElement();
  
  List login = root.getChildren("studentLogin");
  Iterator i = login.iterator();
  System.out.println("Number of nodes  "+login.size() );
  while(i.hasNext()){
  Element user = (Element)i.next();
  
  String userID = root.getChildText("userID");
  String password = root.getChildText("password");
  }
 }
 public static void main (String[] args) 
 {
  System.out.println ("Parsed Values");
  parseXML xml = new parseXML();
   
xml.process("<?xmlversion=\"1.0\"encoding=\"UTF-8\"?><studentLogin><userID>hanuman</userID><password>maruti</password></studentLogin>");
 }
}
 


---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030708/d849fc13/attachment.htm


More information about the jdom-interest mailing list