tags:

views:

67

answers:

2

Hi.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--This is auto-generated file. Do not change it!-->

<DB>

<foo />

<bar />

</DB>

I have one problem with it - when i start parsing (DOM) it says that document is not valid. I've checked what's wrong and the problem is:

Line: 4 
Column: 6

Error:  Can not find declaration of element 'DB'.

Error Position: <DB>

Pls, help :)

+2  A: 

Without knowing much about how you are parsing the document the only advice I can give is that your parser probably requires a schema or DTD that defines the elements (all elements: DB, foo and bar).

If you don't want to write a schema/DTD another option would be (if possible using your parser) to tell the parser not to validate the file. Some parser implementations allow you to specify a flag that tells it not to validate the document.

DaveJohnston
+2  A: 

XML documents have to well-formed and should be valid. A parser will (almost) never accept a document that is not well-formed and (most) parsers can be be told to check the documents validity.

A document is well-formed if it follows all the syntactic rules labelled as well-formedness rules in the XML specification. This is about correct opening and closing of tags, correct use of attributes and so on.

A document is valid if it is not only well-formed but also conforms to the grammar defined in its own schema, which can be either a document type definition (DTD) or a XML schema definition (XSD).

In your case, the document is obviously well-formed and, because it does not refer to a schema, it is not invalid.

The problem could be, that you told your parser to validate the document, which is simply not possible, because there is no schema. Although, if this was the case, the error message would be terribly misleading...

Andreas_D