1

I am getting the error "The prefix "c" for element "c:de" is not bound." Any clue will be very appreciated.

javax.xml.parsers.DocumentBuilderFactory fac = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl( ); fac.setNamespaceAware(true); org.w3c.dom.Document d = null; javax.xml.parsers.DocumentBuilder builder = fac.newDocumentBuilder(); d = builder.parse("C:/my_folder/my_file.xml"); //the error rises in this line 

my_file.xml is exactly and complete pasted here.

<?xml version="1.0" encoding="UTF-8"?> <c:de format="N" lengthField="0" maxLength="012" minLength="012" name="AMOUNT, TRANSACTION" number="004" subFields="00"/> 
1
  • 1
    I suggest reading up about XML namespaces. Commented May 21, 2014 at 22:10

1 Answer 1

1

Your XML is technically invalid.

The namespace prefix c "MUST be associated with a namespace URI reference in a namespace declaration." (W3). For example, this would work:

<?xml version="1.0" encoding="UTF-8"?> <c:de xmlns:c="http://localhost/" format="N" lengthField="0" maxLength="012" minLength="012" name="AMOUNT, TRANSACTION" number="004" subFields="00"/> 

Note the addition of the xmlns:c attribute. The URI you use in this attribute should be the one that properly identifiies the namespace you intend to use.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Do you know how can I set as answered this question?
@user79885, there should be an outline of a check mark to the left of the answer. If you click that it should fill in green and mark this as the accepted answer. Thanks for doing it, as it will give me points and tell people who are searching for this question in the future that it has been answered.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.