You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by KUHN Jérémy <je...@yahoo.fr> on 2005/04/30 11:31:32 UTC

problem validating Document with dom3

Hi,

I'm using Java 5 with xerces beta dom3 2.6.2
implementation.

My problem is the following :

When I try to normalize a Document that I've created
in my code I've received the following error :

NullLocalElementName: A null local name was
encountered during namespace normalization of element
item.

My code :

try
		{
		
System.setProperty(DOMImplementationRegistry.PROPERTY,"org.apache.xerces.dom.DOMImplementationSourceImpl");
			DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
			DOMImplementation impl =
(DOMImplementation)registry.getDOMImplementation("XML
3.0");
	Document doc =
impl.createDocument(null,"simple",null);
			
	Element item = doc.createElement("item");
			item.appendChild(doc.createTextNode("plip"));
			
			doc.getDocumentElement().appendChild(item);
			
	DOMConfiguration config = doc.getDomConfig();
			config.setParameter("validate",Boolean.TRUE);
			config.setParameter("error-handler",new
DOMErrorHandler() {
			
	public boolean handleError(DOMError error) {	
System.out.println(error.getMessage());
			return false;
		}			
	});
		
config.setParameter("schema-type","http://www.w3.org/2001/XMLSchema");
		
config.setParameter("schema-location","simple.xsd");
			
	doc.normalizeDocument();
			
	OutputFormat format = new OutputFormat(doc);
	format.setIndenting(true);
	XMLSerializer serial = new
XMLSerializer(System.out,format);
	serial.asDOMSerializer();
	serial.serialize(doc);
			
}
catch (ClassCastException e)
{
	e.printStackTrace();
}

The corresponding schema :

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="simple" type="simpleType"/>

<xs:complexType name="simpleType">
	<xs:sequence>
		<xs:element name="item" type="xs:string"/>
	</xs:sequence>
</xs:complexType>

</schema>

The interesting thing is that when I parse a valid XML
file with DOMImplementationLS and I normalize it
after, it's working fine without any error message.

Maybe it's a problem of parameters in the
DOMConfiguration.

Any ideas?



	

	
		
__________________________________________________________________ 
Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails ! 
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: problem validating Document with dom3

Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hi,

	Use createElementNS rather than createElement. The second is a DOM  
level 1 method and was before we had namespace and localname.

Cheers,

Gareth

On 30 Apr 2005, at 10:31, KUHN Jérémy wrote:

> Hi,
>
> I'm using Java 5 with xerces beta dom3 2.6.2
> implementation.
>
> My problem is the following :
>
> When I try to normalize a Document that I've created
> in my code I've received the following error :
>
> NullLocalElementName: A null local name was
> encountered during namespace normalization of element
> item.
>
> My code :
>
> try
> 		{
> 		
> System.setProperty(DOMImplementationRegistry.PROPERTY,"org.apache.xerce 
> s.dom.DOMImplementationSourceImpl");
> 			DOMImplementationRegistry registry =
> DOMImplementationRegistry.newInstance();
> 			DOMImplementation impl =
> (DOMImplementation)registry.getDOMImplementation("XML
> 3.0");
> 	Document doc =
> impl.createDocument(null,"simple",null);
> 			
> 	Element item = doc.createElement("item");
> 			item.appendChild(doc.createTextNode("plip"));
> 			
> 			doc.getDocumentElement().appendChild(item);
> 			
> 	DOMConfiguration config = doc.getDomConfig();
> 			config.setParameter("validate",Boolean.TRUE);
> 			config.setParameter("error-handler",new
> DOMErrorHandler() {
> 			
> 	public boolean handleError(DOMError error) {	
> System.out.println(error.getMessage());
> 			return false;
> 		}			
> 	});
> 		
> config.setParameter("schema-type","http://www.w3.org/2001/XMLSchema");
> 		
> config.setParameter("schema-location","simple.xsd");
> 			
> 	doc.normalizeDocument();
> 			
> 	OutputFormat format = new OutputFormat(doc);
> 	format.setIndenting(true);
> 	XMLSerializer serial = new
> XMLSerializer(System.out,format);
> 	serial.asDOMSerializer();
> 	serial.serialize(doc);
> 			
> }
> catch (ClassCastException e)
> {
> 	e.printStackTrace();
> }
>
> The corresponding schema :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> <xs:element name="simple" type="simpleType"/>
>
> <xs:complexType name="simpleType">
> 	<xs:sequence>
> 		<xs:element name="item" type="xs:string"/>
> 	</xs:sequence>
> </xs:complexType>
>
> </schema>
>
> The interesting thing is that when I parse a valid XML
> file with DOMImplementationLS and I normalize it
> after, it's working fine without any error message.
>
> Maybe it's a problem of parameters in the
> DOMConfiguration.
>
> Any ideas?
>
>
>
> 	
>
> 	
> 		
> __________________________________________________________________
> Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour  
> vos mails !
> Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
>
--
Gareth Reakes, Managing Director      Parthenon Computing
+44-1865-811184                  http://www.parthcomp.com


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org