You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ro...@apache.org on 2006/12/05 11:58:16 UTC
svn commit: r482588 - in /incubator/tuscany/cpp/sdo/runtime/core:
src/commonj/sdo/ test/
Author: robbinspg
Date: Tue Dec 5 02:58:15 2006
New Revision: 482588
URL: http://svn.apache.org/viewvc?view=rev&rev=482588
Log:
TUSCANY-908 Apply Simon Laws' CDATA patch
Modified:
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.h
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SAX2Parser.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.h
incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp
incubator/tuscany/cpp/sdo/runtime/core/test/cdata-in.xml
incubator/tuscany/cpp/sdo/runtime/core/test/cdata-out.xml
incubator/tuscany/cpp/sdo/runtime/core/test/cdata.xsd
incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.cpp?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.cpp Tue Dec 5 02:58:15 2006
@@ -21,15 +21,13 @@
#include "commonj/sdo/PropertySetting.h"
#include "SDOString.h"
+#include "SDOUtils.h"
namespace commonj
{
namespace sdo
{
- const char *PropertySetting::CDataStartMarker = "XXXCDATA@STARTXXX";
- const char *PropertySetting::XMLCDataStartMarker = "<![CDATA[";
- const char *PropertySetting::CDataEndMarker = "XXXCDATA@ENDX";
- const char *PropertySetting::XMLCDataEndMarker = "]]>";
+
PropertySetting::PropertySetting()
: dataObject(NULL), isNULL(false), isIDREF(false), pendingUnknownType(false)
@@ -43,64 +41,28 @@
{
}
- PropertySetting::~PropertySetting()
- {
- }
-
- /*
- * A local utility function that replaces one string with and another within a
- * host string and adjusts the lenght of the host string accordingly.
- */
- SDOString replace(SDOString hostString, const char *fromString, const char *toString)
- {
- SDOString returnString("");
-
- // find and replace all occurances of fromString with toString. The start, end
- // and length variables are used to indicate the start, end and length
- // of the text sections to be copied from the host string to the return
- // string. toString is appended in between these copied sections because the
- // string is broken whenever fronString is found
- std::string::size_type start = 0;
- std::string::size_type end = hostString.find(fromString, 0);
- std::string::size_type length = 0;
-
- while ( end != std::string::npos )
- {
- // copy all the text up to the fromString
- length = end - start;
- returnString.append(hostString.substr(start, length));
-
- // add in the toString
- returnString.append(toString);
-
- // find the next fromString
- start = end + strlen(fromString);
- end = hostString.find(fromString, start);
- }
-
- // copy any text left at the end of the host string
- returnString.append(hostString.substr(start));
-
- return returnString;
- }
-
- /*
- * The value that PropertySetting uses to hold values passing from
- * an input XML stream to data object properties is currently an SDOXMLString
- * SDOXMLString use libxml2 functions to do it's thing and in the process messes
- * up CDATA markers. To avoid this we use our own version of CDATA makers and
- * use this method to replace them with the real ones just before the PropertSetting
- * gets committed to the SDO proper in SDOSAX2Parser
- */
- SDOString PropertySetting::getStringWithCDataMarkers()
- {
- SDOString valueString((const char*)value);
-
- SDOString returnString = replace(valueString, CDataStartMarker, XMLCDataStartMarker);
- returnString = replace(returnString, CDataEndMarker, XMLCDataEndMarker);
+ PropertySetting::~PropertySetting()
+ {
+ }
+
+
+ /*
+ * The value that PropertySetting uses to hold values passing from
+ * an input XML stream to data object properties is currently an SDOXMLString
+ * SDOXMLString use libxml2 functions to do it's thing and in the process messes
+ * up CDATA markers. To avoid this we use our own version of CDATA makers and
+ * use this method to replace them with the real ones just before the PropertSetting
+ * gets committed to the SDO proper in SDOSAX2Parser
+ */
+ SDOString PropertySetting::getStringWithCDataMarkers()
+ {
+ SDOString valueString((const char*)value);
+
+ SDOString returnString = SDOUtils::replace(valueString, SDOUtils::CDataStartMarker, SDOUtils::XMLCDataStartMarker);
+ returnString = SDOUtils::replace(returnString, SDOUtils::CDataEndMarker, SDOUtils::XMLCDataEndMarker);
- return returnString;
- }
+ return returnString;
+ }
} // End - namespace sdo
} // End - namespace commonj
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.h?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/PropertySetting.h Tue Dec 5 02:58:15 2006
@@ -48,7 +48,7 @@
bool isIDREF=false);
virtual ~PropertySetting();
- SDOString getStringWithCDataMarkers();
+ SDOString getStringWithCDataMarkers();
SDOXMLString name;
SDOXMLString value;
@@ -56,17 +56,7 @@
bool isIDREF;
bool isNULL;
bool pendingUnknownType;
-
- /*
- * Markers used to represent the start and end of CDATA sections in the
- * settings value. The noew XML CDATA markers are not used here because the
- * XML string processing URL encodes parts of the markers
- */
- static SDO_API const char *CDataStartMarker;
- static SDO_API const char *XMLCDataStartMarker;
- static SDO_API const char *CDataEndMarker;
- static SDO_API const char *XMLCDataEndMarker;
-
+
};
} // End - namespace sdo
} // End - namespace commonj
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SAX2Parser.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SAX2Parser.cpp?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SAX2Parser.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SAX2Parser.cpp Tue Dec 5 02:58:15 2006
@@ -22,7 +22,7 @@
#include "commonj/sdo/SAX2Parser.h"
#include "libxml/SAX2.h"
#include "commonj/sdo/SDORuntimeException.h"
-#include "commonj/sdo/PropertySetting.h"
+#include "commonj/sdo/SDOUtils.h"
using namespace commonj::sdo;
/**
@@ -168,16 +168,16 @@
void sdo_cdataBlock(void *ctx, const xmlChar *value, int len)
{
- if (!((SAX2Parser*)ctx)->parserError)
- {
- SDOXMLString valueAsString(value, 0, len);
-
- SDOXMLString cdata(PropertySetting::CDataStartMarker);
- cdata = cdata + valueAsString;
- cdata = cdata + PropertySetting::CDataEndMarker;
+ if (!((SAX2Parser*)ctx)->parserError)
+ {
+ SDOXMLString valueAsString(value, 0, len);
+
+ SDOXMLString cdata(SDOUtils::CDataStartMarker);
+ cdata = cdata + valueAsString;
+ cdata = cdata + SDOUtils::CDataEndMarker;
- ((SAX2Parser*)ctx)->characters(cdata);
- }
+ ((SAX2Parser*)ctx)->characters(cdata);
+ }
}
void sdo_comment(void *ctx, const xmlChar *value)
@@ -526,5 +526,4 @@
} // End - namespace sdo
} // End - namespace commonj
-
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp Tue Dec 5 02:58:15 2006
@@ -32,6 +32,7 @@
#include "commonj/sdo/TypeImpl.h"
#include "commonj/sdo/DataObjectImpl.h"
#include "commonj/sdo/DataFactoryImpl.h"
+#include "commonj/sdo/SDOUtils.h"
#include <stdio.h>
using namespace std;
@@ -1334,11 +1335,18 @@
DataObject* dob = currentDataObject;
if ((dob != 0) && ((DataObjectImpl*)dob)->getTypeImpl().isFromList())
{
- // this is a list,so we need to split it up
+ // this is a list,so we need to split it up
DataObjectList& dl = currentDataObject->getList(
(const char *)"values");
const char* str = (const char*)chars;
+
+ // Convert any synthetic CDATA markers back to the real thing
+ SDOString valueString(str);
+ SDOString tmpString = SDOUtils::replace(valueString, SDOUtils::CDataStartMarker, SDOUtils::XMLCDataStartMarker);
+ tmpString = SDOUtils::replace(tmpString, SDOUtils::CDataEndMarker, SDOUtils::XMLCDataEndMarker);
+ str = (const char*)tmpString.c_str();
+
char* buf = new char[strlen(str)+1];
if (!buf) return;
@@ -1371,12 +1379,20 @@
// then add this as text to the sequence
if (currentDataObject && currentDataObjectType->isSequencedType())
{
+ // Convert any synthetic CDATA markers back to the real thing
+ const char* str = (const char*)chars;
+
+ SDOString valueString(str);
+ SDOString tmpString = SDOUtils::replace(valueString, SDOUtils::CDataStartMarker, SDOUtils::XMLCDataStartMarker);
+ tmpString = SDOUtils::replace(tmpString, SDOUtils::CDataEndMarker, SDOUtils::XMLCDataEndMarker);
+ str = tmpString.c_str();
+
SequencePtr seq = currentDataObject->getSequence();
if (seq)
{
if (newSequence == true)
{
- seq->addText(chars);
+ seq->addText(str);
newSequence = false;
}
else
@@ -1390,20 +1406,20 @@
if (s)
{
char *combi =
- new char[strlen(s)+strlen(chars) + 2];
+ new char[strlen(s)+strlen(str) + 2];
strcpy(combi,s);
- strcat(combi,chars);
+ strcat(combi,str);
seq->setText(k,(const char*)combi);
delete combi;
}
else
{
- seq->setText(k,chars);
+ seq->setText(k,str);
}
return;
}
}
- seq->addText(chars);
+ seq->addText(str);
}
return;
}
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.cpp Tue Dec 5 02:58:15 2006
@@ -29,6 +29,11 @@
namespace commonj {
namespace sdo {
+
+ const char *SDOUtils::CDataStartMarker = "XXXCDATA@STARTXXX";
+ const char *SDOUtils::XMLCDataStartMarker = "<![CDATA[";
+ const char *SDOUtils::CDataEndMarker = "XXXCDATA@ENDX";
+ const char *SDOUtils::XMLCDataEndMarker = "]]>";
//////////////////////////////////////////////////////////////////////////
// Conversions
@@ -247,6 +252,44 @@
}
}
+
+ /*
+ * A local utility function that replaces one string with and another within a
+ * host string and adjusts the lenght of the host string accordingly.
+ */
+ SDOString SDOUtils::replace(SDOString hostString, const char *fromString, const char *toString)
+ {
+ SDOString returnString("");
+
+ // find and replace all occurances of fromString with toString. The start, end
+ // and length variables are used to indicate the start, end and length
+ // of the text sections to be copied from the host string to the return
+ // string. toString is appended in between these copied sections because the
+ // string is broken whenever fromString is found
+ std::string::size_type start = 0;
+ std::string::size_type end = hostString.find(fromString, 0);
+ std::string::size_type length = 0;
+
+ while ( end != std::string::npos )
+ {
+ // copy all the text up to the fromString
+ length = end - start;
+ returnString.append(hostString.substr(start, length));
+
+ // add in the toString
+ returnString.append(toString);
+
+ // find the next fromString
+ start = end + strlen(fromString);
+ end = hostString.find(fromString, start);
+ }
+
+ // copy any text left at the end of the host string
+ returnString.append(hostString.substr(start));
+
+ return returnString;
+ }
+
};
};
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.h?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOUtils.h Tue Dec 5 02:58:15 2006
@@ -46,6 +46,17 @@
static SDO_API const char* SDOToXSD(const char* sdoname);
static SDO_API const char* XSDToSDO(const char* xsdname);
static void printTypes(std::ostream& out, DataFactoryPtr df);
+ static SDOString replace(SDOString hostString, const char *fromString, const char *toString);
+
+ /*
+ * Markers used to represent the start and end of CDATA sections in the
+ * settings value. The noew XML CDATA markers are not used here because the
+ * XML string processing URL encodes parts of the markers
+ */
+ static SDO_API const char *CDataStartMarker;
+ static SDO_API const char *XMLCDataStartMarker;
+ static SDO_API const char *CDataEndMarker;
+ static SDO_API const char *XMLCDataEndMarker;
private:
Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp Tue Dec 5 02:58:15 2006
@@ -727,6 +727,7 @@
}
else
{
+ /* Use our wrapper function just in case the element has CDATA in it */
writeXMLElement(writer,
elementName,
dataObject->getCString(""));
@@ -1047,7 +1048,9 @@
if (sequence->isText(i))
{
- rc = xmlTextWriterWriteString(
+ // This is a raw write rather than xmlTextWriterWriteString
+ // just in case the text has a CDATA section in it
+ rc = xmlTextWriterWriteRaw(
writer,
SDOXMLString(sequence->getCStringValue(i)));
continue;
@@ -1088,10 +1091,16 @@
else
{
// Sequence member is a primitive
+ /* Use our wrapper function just in case the element has CDATA in it */
+ writeXMLElement(writer,
+ seqPropName,
+ sequence->getCStringValue(i));
+ /*
xmlTextWriterWriteElement(
writer,
seqPropName,
SDOXMLString(sequence->getCStringValue(i)));
+ */
} // end DataType
} // end - iterate over sequence
@@ -1290,7 +1299,7 @@
/**
* A wrapper for the libxml2 function xmlTextWriterWriteElement
- * it detects CDATA sections before wrting out element contents
+ * it detects CDATA sections before writing out element contents
*/
int SDOXMLWriter::writeXMLElement(xmlTextWriterPtr writer,
const xmlChar *name,
@@ -1301,6 +1310,8 @@
rc = xmlTextWriterWriteRaw(writer, SDOXMLString(content));
rc = xmlTextWriterEndElement(writer);
/* A more complex version that doesn't work!
+ * I've left it here just in case we need to go back and separate out
+ * CDATA from text. This might provide a starting point
SDOString contentString(content);
// write the start of the element. we could write a mixture of
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/cdata-in.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/cdata-in.xml?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/cdata-in.xml (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/cdata-in.xml Tue Dec 5 02:58:15 2006
@@ -24,5 +24,6 @@
<fred>abcdefg</fred>
<fred><![CDATA[>>>>>>>>>]]></fred>
<fred>xxx<![CDATA[<?xml version="1.0"encoding="UTF-8"?><MOREXML>....</MOREXML>]]>aaaa<![CDATA[>>>>>>>>>]]></fred>
+ <jim>xxx<![CDATA[<?xml version="1.0"encoding="UTF-8"?><MOREXML>....</MOREXML>]]>aaaa<![CDATA[>>>>>>>>>]]></jim>
</entry1>
</tns:test>
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/cdata-out.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/cdata-out.xml?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/cdata-out.xml (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/cdata-out.xml Tue Dec 5 02:58:15 2006
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
-<test xmlns="http://www.example.org/test" xmlns:tns="http://www.example.org/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><entry1><data>xxx<![CDATA[<?xml version="1.0"encoding="UTF-8"?><MOREXML>....</MOREXML>]]>aaaa<![CDATA[>>>>>>>>>]]></data><fred>abcdefg</fred><fred><![CDATA[>>>>>>>>>]]></fred><fred>xxx<![CDATA[<?xml version="1.0"encoding="UTF-8"?><MOREXML>....</MOREXML>]]>aaaa<![CDATA[>>>>>>>>>]]></fred></entry1></test>
+<test xmlns="http://www.example.org/test" xmlns:tns="http://www.example.org/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><entry1><data>xxx<![CDATA[<?xml version="1.0"encoding="UTF-8"?><MOREXML>....</MOREXML>]]>aaaa<![CDATA[>>>>>>>>>]]></data><fred>abcdefg</fred><fred><![CDATA[>>>>>>>>>]]></fred><fred>xxx<![CDATA[<?xml version="1.0"encoding="UTF-8"?><MOREXML>....</MOREXML>]]>aaaa<![CDATA[>>>>>>>>>]]></fred><jim xsi:type="OpenDataObject">xxx<![CDATA[<?xml version="1.0"encoding="UTF-8"?><MOREXML>....</MOREXML>]]>aaaa<![CDATA[>>>>>>>>>]]></jim></entry1></test>
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/cdata.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/cdata.xsd?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/cdata.xsd (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/cdata.xsd Tue Dec 5 02:58:15 2006
@@ -28,6 +28,7 @@
<sequence>
<element name="data" type="string"/>
<element name="fred" type="string" maxOccurs="unbounded"/>
+ <any namespace="##any" processContents="lax"/>
</sequence>
</complexType>
</element>
Modified: incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp?view=diff&rev=482588&r1=482587&r2=482588
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp Tue Dec 5 02:58:15 2006
@@ -9056,71 +9056,71 @@
int sdotest::cdatatest()
{
- try
- {
- DataFactoryPtr mdg = DataFactory::getDataFactory();
-
- /**
- * Get an XSD helper to load XSD information into the
- * data factory
- */
- XSDHelperPtr myXSDHelper = HelperProvider::getXSDHelper(mdg);
- myXSDHelper->defineFile("cdata.xsd");
-
- /**
- * Check if there were any errors. The parse may still
- * succeed, but errors indicate some elements were not
- * understood
- */
- unsigned int i = 0;
- unsigned int j = 0;
- if ((i = myXSDHelper->getErrorCount()) > 0)
- {
- cout << "XSD Loading reported some errors:" << endl;
- for (j=0;j<i;j++)
- {
- const char *m = myXSDHelper->getErrorMessage(j);
- if (m != 0) cout << m;
- cout << endl;
- return 0;
- }
- }
-
- /**
- * Use the same data factory to load XML corresponding to
- * data objects adhering to the previously loaded schema
- */
- XMLHelperPtr myXMLHelper = HelperProvider::getXMLHelper(mdg);
- XMLDocumentPtr myXMLDocument = myXMLHelper->loadFile("cdata-in.xml", "http://www.example.org/test");
-
- /**
- * Check if there were any errors. The parse may still
- * succeed, but errors indicate some elements did not match
- * the schema, or were malformed.
- *
- */
- if ((i = myXMLHelper->getErrorCount()) > 0)
- {
- cout << "XML Loading reported some errors:" << endl;
- for (j=0;j<i;j++)
- {
- const char *m = myXMLHelper->getErrorMessage(j);
- if (m != 0) cout << m;
- cout << endl;
- return 0;
- }
- }
-
- // write the XML element back out to a file
- myXMLHelper->save(myXMLDocument, "cdata-testout.xml");
-
- return comparefiles("cdata-out.xml","cdata-testout.xml");
-
- }
- catch (SDORuntimeException e)
- {
- cout << "Exception in interop test" << endl;
- cout << e.getMessageText();
- return 0;
- }
+ try
+ {
+ DataFactoryPtr mdg = DataFactory::getDataFactory();
+
+ /**
+ * Get an XSD helper to load XSD information into the
+ * data factory
+ */
+ XSDHelperPtr myXSDHelper = HelperProvider::getXSDHelper(mdg);
+ myXSDHelper->defineFile("cdata.xsd");
+
+ /**
+ * Check if there were any errors. The parse may still
+ * succeed, but errors indicate some elements were not
+ * understood
+ */
+ unsigned int i = 0;
+ unsigned int j = 0;
+ if ((i = myXSDHelper->getErrorCount()) > 0)
+ {
+ cout << "XSD Loading reported some errors:" << endl;
+ for (j=0;j<i;j++)
+ {
+ const char *m = myXSDHelper->getErrorMessage(j);
+ if (m != 0) cout << m;
+ cout << endl;
+ return 0;
+ }
+ }
+
+ /**
+ * Use the same data factory to load XML corresponding to
+ * data objects adhering to the previously loaded schema
+ */
+ XMLHelperPtr myXMLHelper = HelperProvider::getXMLHelper(mdg);
+ XMLDocumentPtr myXMLDocument = myXMLHelper->loadFile("cdata-in.xml", "http://www.example.org/test");
+
+ /**
+ * Check if there were any errors. The parse may still
+ * succeed, but errors indicate some elements did not match
+ * the schema, or were malformed.
+ *
+ */
+ if ((i = myXMLHelper->getErrorCount()) > 0)
+ {
+ cout << "XML Loading reported some errors:" << endl;
+ for (j=0;j<i;j++)
+ {
+ const char *m = myXMLHelper->getErrorMessage(j);
+ if (m != 0) cout << m;
+ cout << endl;
+ return 0;
+ }
+ }
+
+ // write the XML element back out to a file
+ myXMLHelper->save(myXMLDocument, "cdata-testout.xml");
+
+ return comparefiles("cdata-out.xml","cdata-testout.xml");
+
+ }
+ catch (SDORuntimeException e)
+ {
+ cout << "Exception in interop test" << endl;
+ cout << e.getMessageText();
+ return 0;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org