|
|
Re: CDATA appearing in xsd:any data [message #1386079 is a reply to message #1386031] |
Fri, 13 June 2014 11:14 |
Rob Mising name Messages: 118 Registered: July 2010 |
Senior Member |
|
|
OK, I have looked a little further into this, it appears that whenever data is stored into an "xsd:any" it assumes that it is "mixed xml" - this means that it always believes that it should print it exactly as the input data. When mixed isn't supported for the XML added to the xsd:any, then this isn't normally a problem as it would just be white space - which will be ignored within the generated XML.
However, when you set EMF to add CDATA to everything - then it will detect this white-space between elements - and add a CDATA around it. (Which may not be valid if the original schema for the object stored into the xsd:any did not support mixed)
I have managed to work around this by editing XMLSaveImpl in the method saveElementFeatureMap, so that in the if for "MLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT" we now have:
if (entryFeature == XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT)
{
String svalue = value.toString();
if (escape != null)
{
boolean convertTxt = true;
// CHANGE START
// This could be done in a single line, but it is quite hard to
// work out the rules when viewed this way, so I have split it
// into several lines
if (usingCData)
{
if ((o instanceof AnyType) && (f instanceof EAttribute))
{
if (svalue.trim().length() == 0)
{
convertTxt = false;
}
}
}
// CHANGE END
if( convertTxt )
{
svalue = escape.convertText(svalue);
}
}
if (!toDOM)
{
doc.addText(svalue);
}
else
{
Node text = document.createTextNode(svalue);
currentNode.appendChild(text);
handler.recordValues(text, o, f, entry);
}
}
The "usingCData" variable is the value read out of the passed in options to "init".
|
|
|
Powered by
FUDForum. Page generated in 0.03215 seconds