XML.save() dropped double quotation marks because " parsing
DenisNovac opened this issue · 8 comments
Hi everyone. I've read this lines with XML.loadFile(path)
:
<modified comment="EDITED oval:org.mitre.oval:obj:6886 - Adding the '<behaviors windows_view="32_bit" />' for oval:org.mitre.oval:obj:6886." date="2013-05-07T09:28:00.207-04:00">
<contributor organization="ALTX-SOFT">Sergey Artykhov</contributor>
</modified>
Then i saved them with XML.save(filepath, xml)
. Now i want to read this file back, but i can't:
Exception in thread "main" org.xml.sax.SAXParseException; lineNumber: 45; columnNumber: 82; Element type "modified" must be followed by either attribute specifications, ">" or "/>".
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1471)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.seekCloseOfStartTag(XMLDocumentFragmentScannerImpl.java:1433)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1362)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2710)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:324)
at scala.xml.factory.XMLLoader.loadXML(XMLLoader.scala:41)
at scala.xml.factory.XMLLoader.loadXML$(XMLLoader.scala:37)
at scala.xml.XML$.loadXML(XML.scala:58)
at scala.xml.factory.XMLLoader.loadFile(XMLLoader.scala:48)
at scala.xml.factory.XMLLoader.loadFile$(XMLLoader.scala:48)
at scala.xml.XML$.loadFile(XML.scala:58)
at composer.OvalIndexer$.$anonfun$indexDefinitions$1(OvalIndexer.scala:43)
at scala.collection.StrictOptimizedIterableOps.map(StrictOptimizedIterableOps.scala:100)
at scala.collection.StrictOptimizedIterableOps.map$(StrictOptimizedIterableOps.scala:87)
at scala.collection.immutable.Vector.map(Vector.scala:119)
at composer.OvalIndexer$.indexDefinitions(OvalIndexer.scala:40)
at composer.OvalIndexer$.createIndex(OvalIndexer.scala:30)
at Main$.main(Main.scala:11)
at Main.main(Main.scala)
Inside my file:
<modified comment='EDITED oval:org.mitre.oval:obj:6886 - Adding the '<behaviors windows_view="32_bit" />' for oval:org.mitre.oval:obj:6886.' date="2013-05-07T09:28:00.207-04:00">
<contributor organization="ALTX-SOFT">Sergey Artykhov</contributor>
</modified>
Looks like double quotation marks were lost somehow.
More examples:
Before:
<modified comment="EDITED oval:org.mitre.oval:obj:30168 - In some "pattern match" strings added "\" before "." to clarify if "point" or "any symbol" needed." date="2014-07-28T18:11:00.493-04:00">
<contributor organization="ALTX-SOFT">Evgeniy Pavlov</contributor>
After:
<modified comment='EDITED oval:org.mitre.oval:obj:30168 - In some "pattern match" strings added "\" before "." to clarify if "point" or "any symbol" needed.' date="2014-07-28T18:11:00.493-04:00">
<contributor organization="ALTX-SOFT">Evgeniy Pavlov</contributor>
</modified>
I've also tried to load XML like this:
val spf = SAXParserFactory.newInstance()
spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)
spf.setFeature("http://xml.org/sax/features/external-general-entities", false)
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
val saxParser = spf.newSAXParser()
val xml_parse = XML.withSAXParser(saxParser).loadFile(path)
But after saving XMLs are still broken.
Looks like it is a defect in 2.0.0-M1. If so, then it would mean #279 is a likely suspect. I only expected that change to affect PCDATA and CDATA. I didn't realize Text
is used in the implementation for attributes. We'll need to either rework that change or revert it.
Switched to 1.2.0 and the error gone.
Glad to hear that. We'll work on fixing in 2.0.0-M2. I appreciate you bothering to report this.
@DenisNovac nice catch! thanks for testing the milestone
No problem c:
One option is implementing something called AttributeText
that is very similar to Text
.