Hi Michael,
I finally found where the error came from.
A DOM object (the Namespace 'ns1' is not declared):
<ele1>
<ele ns1:attr1="val1">
</ele1>
 
If I use Saxon to convert a org.w3c.dom.Document object to xml file, there will be
net.sf.saxon.trans.XPathException: Undeclared namespace in ns1:attr1
 
If I use Xalan and Jdom, there will be no error and the result will be
<ele1>
<ele attr1="val1">
</ele1>
The namespace 'ns1' is deleted automatically. So the output .xml file of Xalan and Jdom
is not equal to the Dom ojbect.
 
Saxon indeed do more validation. I had corrected the DOM object.
Thanks.
 
 
2011-10-24

dba03

发件人: Michael Kay
发送时间: 2011-10-23  01:51:39
收件人: saxon-help
抄送:
主题: Re: [saxon] net.sf.saxon.trans.XPathException: Undeclared namespace
To help with this, I will need to know what is in the DOM node (doc). Can you send a program that I can execute to demonstrate the problem?

It is possible to construct a DOM in which there are elements or attributes having a prefixed name, where the prefix is not declared in any containing element. That is, a DOM representing a non-namespace-well-formed document. If your DOM is not namespace-well-formed, Saxon will not be able to process it. It's quite possible that other products will be able to process it, either because they are deliberately more liberal in what they accept, or because they do less validation.

I don't think the email message you found with a similar error is directly relevant.

Michael Kay
Saxonica

On 22/10/2011 15:46, dba03 wrote:
Hi,
I use the following code to convert a org.w3c.dom.Document object to xml file.
public void domToInputStream(Document doc, String _strFilePat)
{
TransformerFactory transFactory = TransformerFactory.newInstance(); 
Transformer transFormer = transFactory.newTransformer();
DOMSource domSource = new DOMSource(doc); 
File file = createNewFile(_strFilePath); 
FileOutputStream out = new FileOutputStream(file); 
StreamResult xmlResult = new StreamResult(out); 
transFormer.transform(domSource, xmlResult);
}

But errors:
net.sf.saxon.trans.XPathException: Undeclared namespace in 表:name at net.sf.saxon.dom.DOMSender.outputElement(DOMSender.java:214) at net.sf.saxon.dom.DOMSender.walkNode(DOMSender.java:145) at net.sf.saxon.dom.DOMSender.outputElement(DOMSender.java:228) at net.sf.saxon.dom.DOMSender.walkNode(DOMSender.java:145) at net.sf.saxon.dom.DOMSender.outputElement(DOMSender.java:228) at net.sf.saxon.dom.DOMSender.walkNode(DOMSender.java:145) at net.sf.saxon.dom.DOMSender.outputElement(DOMSender.java:228) at net.sf.saxon.dom.DOMSender.walkNode(DOMSender.java:145) at net.sf.saxon.dom.DOMSender.outputElement(DOMSender.java:228) at net.sf.saxon.dom.DOMSender.walkNode(DOMSender.java:145) at net.sf.saxon.dom.DOMSender.send(DOMSender.java:97) at net.sf.saxon.dom.DOMObjectModel.sendSource(DOMObjectModel.java:112) at net.sf.saxon.event.Sender.send(Sender.java:218) at net.sf.saxon.IdentityTransformer.transform(IdentityTransformer.java:29) at common.TranslatorUtils.domToInputStream(TranslatorUtils.java:347)

 Undeclared namespace in 表:name, is a Chinese character.

If I replace saxon9.jar and saxon9-dom.jar with Xalan.jar, there is no errors.

If I use Jdom(http://www.jdom.org/) to implement the function "domToInputStream", there is no errors, too.
public void domToInputStream(Document doc, String _strFilePat)
{   
DOMBuilder builder = new DOMBuilder();   
XMLOutputter xml = new XMLOutputter();   
String s = xml.outputString(builder.build(document));
 ..........
}

I have read the following email.
 "表:name"(Chinese) is not a legal attribute name?
Thanks.






------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help