Closed scabug closed 13 years ago
Imported From: https://issues.scala-lang.org/browse/SI-1626?orig=1 Reporter: Bruno Bieth (mustaghattack) Attachments:
Geoffrey Alan Washburn (washburn) said: The problem has nothing to do with projecting the namespace. Just writing
val n = <a xmlns=""/>
will cause the failure.
I can't seem to find the XML maintainer in the users list. Does anyone if he even has an account?
@cunei said: The XML maintainer can be contacted from this page: [http://www.scala-lang.org/node/292]. Just click on the maintainer's name and you will reach the corresponding contact form.
@michelou said:
From the file header of class scala.xml.NamespaceBinding
one can read:
/** The class <code>NamespaceBinding</code> represents namespace bindings
* and scopes. The binding for the default namespace is treated as a null
* prefix. the absent namespace is represented with the null uri. Neither
* prefix nor uri may be empty, which is not checked.
*
* @author Burak Emir
* @version 1.0
*/
That means that with the current implementation of NamespaceBinding
the uri may not be empty and is not checked.
Geoffrey Alan Washburn (washburn) said: Replying to [comment:3 michelou]:
From the file header of class
scala.xml.NamespaceBinding
one can read: {code} /** The classNamespaceBinding
represents namespace bindings
- and scopes. The binding for the default namespace is treated as a null
- prefix. the absent namespace is represented with the null uri. Neither
- prefix nor uri may be empty, which is not checked.
- @author Burak Emir
- @version 1.0 */ }} That means that with the current implementation of
NamespaceBinding
the uri may not be empty and is not checked.
Okay, but to my knowledge this is valid XML, so it probably should work by default.
Bruno Bieth (mustaghattack) said: Replying to [comment:1 washburn]:
The problem has nothing to do with projecting the namespace. Just writing {code} val n = }} will cause the failure.
I can't seem to find the XML maintainer in the users list. Does anyone if he even has an account?
Where did I write that projecting the namespace would cause the failure ?
I'm just saying that the XML parser should understand standard XML, so I can express this in scala :
<root xmlns="root-ns">
<noNsElement xmlns=""/>
</root>
Geoffrey Alan Washburn (washburn) said: Replying to [comment:5 mustaghattack]:
Where did I write that projecting the namespace would cause the failure ?
Then why did you bother including it in your example?
Bruno Bieth (mustaghattack) said: To show my expectation. As xmlns="" can't be used at the moment, I would expect it to be parsed as a null namespace.
Maybe this wasn't clear enough.
Bruno
Bruno Bieth (mustaghattack) said: More over I would expect the following :
val n = <a xmlns=""/>
n.toString == """<a xmlns=""></a>"""
Cause at the moment I find this quite ugly :
val n = xml.XML.loadString("""<a xmlns=""/>""")
n.toString == """<a xmlns="null"></a>"""
returns true ...
Bruno Bieth (mustaghattack) said: This is also interesting :
xml.XML.loadString("""<a xmlns="cool"><b xmlns=""/></a>""").child.first.toString
returns
<b xmlns="null" xmlns="cool"></b>
Bruno Bieth (mustaghattack) said: A printer that works for empty namespace
Bruno Bieth (mustaghattack) said: As a workaround for those who need empty namespaces to be converted correctly to string, i've created this printer. It's far from good. It doesn't handle comments and stuff, just element and atom nodes. Here are some unit tests :
import org.testng.annotations.Test
import org.testng.Assert._
class EmptyNullNamespacePrinterTest {
val printer = new EmptyNullNamespacePrinter
@Test
def shouldPrintTextNodeAsString {
testXmlStringConversion( """<aNode xmlns="a-ns">Hello<b>Inside B</b> from scala</aNode>""" )
}
@Test
def shouldPrintEmptyNamespaceEmpty {
testXmlStringConversion( """<aNode xmlns="a-ns">Hello<b xmlns="">Inside B<c></c></b> from scala</aNode>""" )
}
@Test
def shouldPrintPCDataNodeAsString {
val s = "a-string"
val r = printer.print( <a>{ s }</a> )
assertEquals( r, "<a>a-string</a>" )
}
protected def testXmlStringConversion( xmlString : String ) {
val r = printer.print( scala.xml.XML.loadString( xmlString ) )
assertEquals( r, xmlString )
}
}
@paulp said: The original report and first bug in comments are fixed in r17604 and r17605. Not sure what's going on with the last bug in comments; please open a new ticket if you think it needs addressing.
I would expect the following to return true
Instead I get :