For example I have following document:
<root>
<prefix:element>
</prefix:element>
</root>
As you can see, namespace with prefix
name undeclared. Is this document is not well-formed?
From w3fools documentation:
A "Well Formed" XML document has correct XML syntax. The syntax rules:
- XML documents must have a root element
- XML elements must have a closing tag
- XML tags are case sensitive
- XML elements must be properly nested
- XML attribute values must be quoted
...nothing about namespaces.
Namespaces in XML is a separate spec from XML 1.0 itself. The example document you give is well-formed XML 1.0 but is not namespace-well-formed according to the namespaces spec, and if you wanted to parse it you'd have to use a parser configured not to be namespace aware.