- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
XML Entity and scala.XML.loadString
Wed, 2010-08-04, 13:14
I have been puzzled by this behavior, when I use the Scala parser to read XML I can load an XML Entity without problem:
scala> <b> </b>
res1: scala.xml.Elem = <b> </b>
scala> res1.child(0).getClass.getSimpleName
res2: java.lang.String = EntityRef
However if I try to read using the scala.xml.XML.loadString I get:
scala> scala.xml.XML.loadString(res1.toString)
org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declare
d.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAX
ParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalErro
r(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(U
nknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanEntityReference(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(U
nknown Source)
at com.sun.org.apache.xe...
I'm using the loadString and load(file) to read snippets of HTML converted to XML (not really XHTML). I would love to have the entities as EntityRef, but I dont know the correct way. Any help on how to do this?
Thomas
Wed, 2010-08-04, 19:57
#2
Re: XML Entity and scala.XML.loadString
You can try to prefix your XML snippets with:
<?xml version="1.0" encoding="utf-8"?>
]>
Depending on how much of the HTML universe you have to deal with, I don't
know if this approach would work.
See if it helps.
On Wed, Aug 4, 2010 at 5:44 PM, Thomas Sant'ana <mailleux@gmail.com> wrote: