Bug 33487

Summary: LSSerializer fails when validating external entities with namespaces
Product: Xerces-J Reporter: ijorge <ijorge>
Component: SAXAssignee: Xerces-J Developers Mailing List <xerces-j-dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description ijorge 2005-02-10 11:33:58 UTC
When I try to write a Document with this code:

System.setProperty(DOMImplementationRegistry.PROPERTY,
                        "org.apache.xerces.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry =
                                   DOMImplementationRegistry.newInstance();

DOMImplementationLS impl =
                      (DOMImplementationLS)registry.getDOMImplementation("LS");
LSOutput output = impl.createLSOutput();
output.setSystemId(uri);
LSSerializer writer = impl.createLSSerializer();
writer.write(document, output);


I recieve this error:
     [java] java.io.IOException: The replacement text of the entity node
'entity' contains an element node 'example1' with an attribute 'xmlns:exa' an
undeclared prefix 'xmlns'.
     [java] 	at org.apache.xml.serialize.BaseMarkupSerializer.fatalError(Unknown
Source)
     [java] 	at
org.apache.xml.serialize.XMLSerializer.checkUnboundNamespacePrefixedNode(Unknown
Source)
     [java] 	at
org.apache.xml.serialize.BaseMarkupSerializer.serializeNode(Unknown Source)
     [java] 	at org.apache.xml.serialize.XMLSerializer.serializeElement(Unknown
Source)
     [java] 	at
org.apache.xml.serialize.BaseMarkupSerializer.serializeNode(Unknown Source)
     [java] 	at
org.apache.xml.serialize.BaseMarkupSerializer.serializeNode(Unknown Source)
     [java] 	at org.apache.xml.serialize.BaseMarkupSerializer.serialize(Unknown
Source)
     [java] 	at org.apache.xml.serialize.DOMSerializerImpl.write(Unknown Source)

These are the xml files that I am using:
XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE Root PUBLIC "-//Example//DTD Example/EN"
"http://www.example.com/example" [

<!ENTITY entity SYSTEM 'entity.inc'>
]>

<Root
 name="root"
 xmlns="http://www.example.com/example"     
 xmlns:exa="http://www.example.com/example">


   &entity;


</Root>

ENTITY:
<?xml version="1.0" encoding="iso-8859-1"?>

<example1 xmlns:exa="http://www.example.com/example">
   <exa:example2>ss</exa:example2>
</example1>


I have been investigating the source code of Xerces and I think that the error
is in org\apache\xerces\util\NamespaceSupport.java. The method "String
getURI(String prefix)" compare two string but uses "==" instead of "equals". I
have modified this code and previous example does not produce errors.

DIFF between original code and my modified code:

232c232
<             if (fNamespace[i - 2] == prefix) {
---
>             if (fNamespace[i - 2].equals(prefix)) {
Comment 1 Michael Glavassevich 2005-02-10 14:06:22 UTC
New bugs, or modifications to existing bugs should be made using JIRA. Some 
time ago tracking of bugs and issues in Xerces moved from Bugzilla to JIRA at: 
http://nagoya.apache.org/jira. Please open this bug report there.

The URL for Xerces in JIRA is: http://issues.apache.org/jira/browse/XERCESJ. In 
order to create a new bug or issue in JIRA, you will need to create a JIRA 
account (assuming you don't already have one).