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

Posted on 2009-02-24
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 javax.xml.parsers.DocumentBuilder.parse(
      at com.pbms.businessLogic.ReadDirectoryWatcherConfFromXML.getFolderDetails(
      at mccprocesswatcher.Main.readRegistrationXMLs(
      at mccprocesswatcher.Main.main(

What is the problem with my XMl file

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

<?xml version="1.0"?>


Please help me out

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
    LVL 86

    Accepted Solution

    You have

    >><?xml version="1.0"?

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


    Author Closing Comment

    Many Thanks It works Great
    LVL 86

    Expert Comment


    Any chance of closing some of your other open qs?

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    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 …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now