You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Christian Koppen (JIRA)" <xa...@xml.apache.org> on 2007/05/02 08:51:15 UTC
[jira] Created: (XALANJ-2382) Namespace declarations are lost on
transformation to DOMResult
Namespace declarations are lost on transformation to DOMResult
--------------------------------------------------------------
Key: XALANJ-2382
URL: https://issues.apache.org/jira/browse/XALANJ-2382
Project: XalanJ2
Issue Type: Bug
Components: DOM, JAXP, Xalan
Affects Versions: 2.7, 2.7.1
Environment: Intel Pentium 4
Windows 2000 SP4
Sun JDK 6 (build 1.6.0-b105)
Reporter: Christian Koppen
Have a look at the following snippet:
<a:a1 xmlns:a="http://a"
xmlns:b="http://b"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<a:a2 xsi:type="b:B"/>
</a:a1>
As you can see, the value of the attribute 'xsi:type' contains a namespace prefix, which is declared in the root element.
When I read this document as a StreamSource or SAXSource and transform it with Xalan into a DOMResult, the namespaces are invalid because the namespace declaration 'xmlns:b="http://b"' is lost:
<a:a1 xmlns:a="http://a">
<a:a2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="b:B"/>
</a:a1>
When I try to read the document as a DOMSource and try to transform it into a DOMResult, an exception occurs ('NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.').
I attach the example code and output.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Commented: (XALANJ-2382) Namespace declarations are lost on
transformation to DOMResult
Posted by "Richard Opalka (JIRA)" <xa...@xml.apache.org>.
[ https://issues.apache.org/jira/browse/XALANJ-2382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12838809#action_12838809 ]
Richard Opalka commented on XALANJ-2382:
----------------------------------------
To workaround your problem with SAXSource
you need to configure SAX stream parser with the following feature
http://xerces.apache.org/xerces2-j/features.html#namespace-prefixes
and associate this reader with SAXSource
For example:
private static final class SAXSourceProvider extends SourceProvider<SAXSource> {
protected SAXSourceProvider(String xml) { super(xml); }
@Override
public SAXSource newSource() throws Exception {
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setNamespaceAware(true);
XMLReader reader = saxFactory.newSAXParser().getXMLReader();
reader.setFeature("http://xml.org/sax/features/namespaces", true);
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); // important - it's false by default
SAXSource retVal = new SAXSource(new InputSource(new StringReader(xml)));
retVal.setXMLReader(reader);
return retVal;
}
}
> Namespace declarations are lost on transformation to DOMResult
> --------------------------------------------------------------
>
> Key: XALANJ-2382
> URL: https://issues.apache.org/jira/browse/XALANJ-2382
> Project: XalanJ2
> Issue Type: Bug
> Components: DOM, JAXP, Xalan
> Affects Versions: 2.7.1, 2.7
> Environment: Intel Pentium 4
> Windows 2000 SP4
> Sun JDK 6 (build 1.6.0-b105)
> Reporter: Christian Koppen
> Attachments: output.txt, TransformerTest.java
>
>
> Have a look at the following snippet:
> <a:a1 xmlns:a="http://a"
> xmlns:b="http://b"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <a:a2 xsi:type="b:B"/>
> </a:a1>
> As you can see, the value of the attribute 'xsi:type' contains a namespace prefix, which is declared in the root element.
> When I read this document as a StreamSource or SAXSource and transform it with Xalan into a DOMResult, the namespaces are invalid because the namespace declaration 'xmlns:b="http://b"' is lost:
> <a:a1 xmlns:a="http://a">
> <a:a2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="b:B"/>
> </a:a1>
> When I try to read the document as a DOMSource and try to transform it into a DOMResult, an exception occurs ('NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.').
> I attach the example code and output.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Commented: (XALANJ-2382) Namespace declarations are lost on
transformation to DOMResult
Posted by "Richard Opalka (JIRA)" <xa...@xml.apache.org>.
[ https://issues.apache.org/jira/browse/XALANJ-2382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12838875#action_12838875 ]
Richard Opalka commented on XALANJ-2382:
----------------------------------------
After applying the patch I'm getting expected output:
class javax.xml.transform.stream.StreamSource
Parsed only : <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
Null-Transform to DOM: <a:a1 xmlns:a="http://a"><a:a2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="b:B"/></a:a1>
class javax.xml.transform.sax.SAXSource
Parsed only : <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
Null-Transform to DOM: <a:a1 xmlns:a="http://a"><a:a2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="b:B"/></a:a1>
class javax.xml.transform.dom.DOMSource
Parsed only : <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
Null-Transform to DOM: <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
class javax.xml.transform.stax.StAXSource
javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:418)
at org.jboss.test.ws.common.xalan.JBWS2917TestCase.transform(JBWS2917TestCase.java:100)
at org.jboss.test.ws.common.xalan.JBWS2917TestCase.main(JBWS2917TestCase.java:69)
> Namespace declarations are lost on transformation to DOMResult
> --------------------------------------------------------------
>
> Key: XALANJ-2382
> URL: https://issues.apache.org/jira/browse/XALANJ-2382
> Project: XalanJ2
> Issue Type: Bug
> Components: DOM, JAXP, Xalan
> Affects Versions: 2.7.1, 2.7
> Environment: Intel Pentium 4
> Windows 2000 SP4
> Sun JDK 6 (build 1.6.0-b105)
> Reporter: Christian Koppen
> Attachments: output.txt, TransformerTest.java, xalan-j2-XALANJ-2382.patch
>
>
> Have a look at the following snippet:
> <a:a1 xmlns:a="http://a"
> xmlns:b="http://b"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <a:a2 xsi:type="b:B"/>
> </a:a1>
> As you can see, the value of the attribute 'xsi:type' contains a namespace prefix, which is declared in the root element.
> When I read this document as a StreamSource or SAXSource and transform it with Xalan into a DOMResult, the namespaces are invalid because the namespace declaration 'xmlns:b="http://b"' is lost:
> <a:a1 xmlns:a="http://a">
> <a:a2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="b:B"/>
> </a:a1>
> When I try to read the document as a DOMSource and try to transform it into a DOMResult, an exception occurs ('NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.').
> I attach the example code and output.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Commented: (XALANJ-2382) Namespace declarations are lost on
transformation to DOMResult
Posted by "Richard Opalka (JIRA)" <xa...@xml.apache.org>.
[ https://issues.apache.org/jira/browse/XALANJ-2382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12838879#action_12838879 ]
Richard Opalka commented on XALANJ-2382:
----------------------------------------
I'm getting this expected output when I apply the patch:
class javax.xml.transform.stream.StreamSource
Parsed only : <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
Null-Transform to DOM: <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
class javax.xml.transform.sax.SAXSource
Parsed only : <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
Null-Transform to DOM: <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
class javax.xml.transform.dom.DOMSource
Parsed only : <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
Null-Transform to DOM: <a:a1 xmlns:a="http://a" xmlns:b="http://b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a:a2 xsi:type="b:B"/></a:a1>
class javax.xml.transform.stax.StAXSource
javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:418)
at org.jboss.test.ws.common.xalan.JBWS2917TestCase.transform(JBWS2917TestCase.java:100)
at org.jboss.test.ws.common.xalan.JBWS2917TestCase.main(JBWS2917TestCase.java:69)
> Namespace declarations are lost on transformation to DOMResult
> --------------------------------------------------------------
>
> Key: XALANJ-2382
> URL: https://issues.apache.org/jira/browse/XALANJ-2382
> Project: XalanJ2
> Issue Type: Bug
> Components: DOM, JAXP, Xalan
> Affects Versions: 2.7.1, 2.7
> Environment: Intel Pentium 4
> Windows 2000 SP4
> Sun JDK 6 (build 1.6.0-b105)
> Reporter: Christian Koppen
> Attachments: output.txt, TransformerTest.java, xalan-j2-XALANJ-2382.patch
>
>
> Have a look at the following snippet:
> <a:a1 xmlns:a="http://a"
> xmlns:b="http://b"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <a:a2 xsi:type="b:B"/>
> </a:a1>
> As you can see, the value of the attribute 'xsi:type' contains a namespace prefix, which is declared in the root element.
> When I read this document as a StreamSource or SAXSource and transform it with Xalan into a DOMResult, the namespaces are invalid because the namespace declaration 'xmlns:b="http://b"' is lost:
> <a:a1 xmlns:a="http://a">
> <a:a2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="b:B"/>
> </a:a1>
> When I try to read the document as a DOMSource and try to transform it into a DOMResult, an exception occurs ('NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.').
> I attach the example code and output.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org
[jira] Commented: (XALANJ-2382) Namespace declarations are lost on
transformation to DOMResult
Posted by "Richard Opalka (JIRA)" <xa...@xml.apache.org>.
[ https://issues.apache.org/jira/browse/XALANJ-2382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12838801#action_12838801 ]
Richard Opalka commented on XALANJ-2382:
----------------------------------------
To fix your problem with NAMESPACE_ERR you need to use namespace aware document builder.
IOW just replace
private static final class DOMSourceProvider extends SourceProvider<DOMSource> {
protected DOMSourceProvider(String xml) { super(xml); }
@Override
public DOMSource newSource() throws Exception {
return new DOMSource(
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
new InputSource(new StringReader(xml))));
}
}
with
private static final class DOMSourceProvider extends SourceProvider<DOMSource> {
protected DOMSourceProvider(String xml) { super(xml); }
@Override
public DOMSource newSource() throws Exception {
DocumentBuilderFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
return new DOMSource(
dbf.newDocumentBuilder().parse(
new InputSource(new StringReader(xml))));
}
}
> Namespace declarations are lost on transformation to DOMResult
> --------------------------------------------------------------
>
> Key: XALANJ-2382
> URL: https://issues.apache.org/jira/browse/XALANJ-2382
> Project: XalanJ2
> Issue Type: Bug
> Components: DOM, JAXP, Xalan
> Affects Versions: 2.7.1, 2.7
> Environment: Intel Pentium 4
> Windows 2000 SP4
> Sun JDK 6 (build 1.6.0-b105)
> Reporter: Christian Koppen
> Attachments: output.txt, TransformerTest.java
>
>
> Have a look at the following snippet:
> <a:a1 xmlns:a="http://a"
> xmlns:b="http://b"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <a:a2 xsi:type="b:B"/>
> </a:a1>
> As you can see, the value of the attribute 'xsi:type' contains a namespace prefix, which is declared in the root element.
> When I read this document as a StreamSource or SAXSource and transform it with Xalan into a DOMResult, the namespaces are invalid because the namespace declaration 'xmlns:b="http://b"' is lost:
> <a:a1 xmlns:a="http://a">
> <a:a2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="b:B"/>
> </a:a1>
> When I try to read the document as a DOMSource and try to transform it into a DOMResult, an exception occurs ('NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.').
> I attach the example code and output.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org