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

Bradley S. Huffman hip at cs.okstate.edu
Tue Jul 8 11:05:05 PDT 2003


Oooo that's a misleading error message. In the declaration put a space between
"xml" and "version".

Brad

Naveen My writes:

> --0-1797426379-1057687132=:81101
> Content-Type: text/plain; charset=us-ascii
> 
> 
> When I run the below program..I get
>  
> org.jdom.input.JDOMParseException: Error on line 1: White space is required b
> etween 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>ha
> numan</userID><password>maruti</password></studentLogin>");
>  }
> }



More information about the jdom-interest mailing list