XML Reading -- The processing instruction target matching "[xX][mM][lL]" is not allowed.

Posted on 2009-02-24
Medium Priority
Last Modified: 2012-05-06

I am reading XML from my java code

I am getting error below:

org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
      at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
      at com.pbms.businessLogic.ReadDirectoryWatcherConfFromXML.getFolderDetails(ReadDirectoryWatcherConfFromXML.java:37)
      at mccprocesswatcher.Main.readRegistrationXMLs(Main.java:66)
      at mccprocesswatcher.Main.main(Main.java:42)

What is the problem with my XMl file

<?xml version="1.0" encoding="UTF-8"?>

<?xml version="1.0"?>


Please help me out
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XMLReader {
 public static void main(String argv[]) {
	File file = new File("/DirectoryWatcherConfig.xml");
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	DocumentBuilder db = dbf.newDocumentBuilder();
	Document doc = db.parse(file);
	System.out.println("Root element " + doc.getDocumentElement().getNodeName());
	NodeList nodeLst = doc.getElementsByTagName("Directory");
	System.out.println("Information of all directories to watch");
	for (int s = 0; s < nodeLst.getLength(); s++) {
	  Node fstNode = nodeLst.item(s);
	  if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
		 Element fstElmnt = (Element) fstNode;
	    NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("DirectoryPath");
	    Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
	    NodeList fstNm = fstNmElmnt.getChildNodes();
	    System.out.println("Path : "  + ((Node) fstNm.item(0)).getNodeValue());
	    NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("Interval");
	    Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
	    NodeList lstNm = lstNmElmnt.getChildNodes();
	    System.out.println("Interval : " + ((Node) lstNm.item(0)).getNodeValue());
	      }catch(Exception e){
       } catch (Exception e) {

Open in new window

Question by:tia_kamakshi
  • 2
LVL 86

Accepted Solution

CEHJ earned 2000 total points
ID: 23724140
You have

>><?xml version="1.0"?

which is not allowed. Get rid of the 2nd one


Author Closing Comment

ID: 31550689
Many Thanks It works Great
LVL 86

Expert Comment

ID: 23724514

Any chance of closing some of your other open qs?

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question