-
Notifications
You must be signed in to change notification settings - Fork 21
Preserve CDATA sections, don't convert them to generic Text nodes. #3368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Imported From: https://issues.scala-lang.org/browse/SI-3368?orig=1 |
Dmitry Grigoriev (dimgel) said:
Currently Scala converts CDATA nodes to Text nodes (cdata-sections=false). The behaviour I (and David Pollak for 3 years ;) advocate for is to see CDATA sections serialized unchanged (cdata-sections=true), because:
So I suggest ticket should be renamed to "Preserve CDATA sections". |
@acruise said: |
Sebastian Nozzi (sebnozzi) said: |
Christian Zahl (aixpower) said: We see two alternatives:
|
@acruise said: |
Michael Beckerle (mbeckerle.dfdl) said: <dfdl:assert testKind="pattern"><![CDATA[(?x) # free form regex
abc # and a comment
# more comment
def # that's all
</dfdl:assert> We have unit tests where that appears as literal XML text in a scala/junit-like test. @Test def testRegexWithFreeFormAndComments3() = {
val testSuite =
<tdml:testSuite suiteName="theSuiteName" xmlns:tns={ tns } xmlns:tdml={ tdml } xmlns:dfdl={ dfdl } xmlns:xsd={ xsd } xmlns:xs={ xsd } xmlns:xsi={ xsi }>
<tdml:defineSchema name="mySchema">
<dfdl:format ref="tns:daffodilTest1"/>
<xsd:element name="data" type="xsd:string" dfdl:lengthKind="delimited">
<xsd:annotation>
<xsd:appinfo source="http://www.ogf.org/dfdl/">
<!-- This assert passes only if free form works, and comments work. -->
<dfdl:assert testKind='pattern'><![CDATA[(?x) # free form
abcd # a comment
# a line with only a comment
123 # another comment
]]></dfdl:assert>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</tdml:defineSchema>
<tdml:parserTestCase xmlns={ tdml } name="testRegex" root="data" model="mySchema">
<tdml:document>
<tdml:documentPart type="text"><![CDATA[abcdef]]></tdml:documentPart>
</tdml:document>
<tdml:errors>
<tdml:error>assertion failed</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
</tdml:testSuite>
val ts = new DFDLTestSuite(testSuite)
ts.runOneTest("testRegex")
} Obviously this regex language, and many other embedded languages, must have the whitespace preserved (especially line endings). @Test def testRegexWithFreeFormAndComments3() = {
val cdataText = """(?x) # free form
abcd # a comment
# a line with only a comment
123 # another comment
"""
val cdata = new scala.xml.PCData(cdataText)
val testSuite =
<tdml:testSuite suiteName="theSuiteName" xmlns:tns={ tns } xmlns:tdml={ tdml } xmlns:dfdl={ dfdl } xmlns:xsd={ xsd } xmlns:xs={ xsd } xmlns:xsi={ xsi }>
<tdml:defineSchema name="mySchema">
<dfdl:format ref="tns:daffodilTest1"/>
<xsd:element name="data" type="xsd:string" dfdl:lengthKind="delimited">
<xsd:annotation>
<xsd:appinfo source="http://www.ogf.org/dfdl/">
<!-- This assert passes only if free form works, and comments work. -->
<dfdl:assert testKind='pattern'>{ cdata }</dfdl:assert>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</tdml:defineSchema>
<tdml:parserTestCase xmlns={ tdml } name="testRegex" root="data" model="mySchema">
<tdml:document>
<tdml:documentPart type="text"><![CDATA[abcdef]]></tdml:documentPart>
</tdml:document>
<tdml:errors>
<tdml:error>assertion failed</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
</tdml:testSuite>
val ts = new DFDLTestSuite(testSuite)
ts.runOneTest("testRegex")
} But.... then that fails because we pretty print these test suites to temp files, and the pretty printer doesn't preserve the contents of the PCData nodes either! |
@som-snytt said (edited on Apr 10, 2015 2:08:23 AM UTC): There's a flag I don't know whether it's considered gauche to track the PR in the comments. |
@adriaanm said: |
@som-snytt said: |
@som-snytt said: |
@som-snytt said: |
Michael Beckerle (mbeckerle.dfdl) said (edited on Jul 29, 2015 1:57:15 PM UTC): (Note: I created scala/scala-xml#74, but will close it out if we determine this issue is actually complete already.) |
@som-snytt said: |
Sort of defeats part of the purpose of using a CDATA...
The text was updated successfully, but these errors were encountered: