Newbie problems migrating XercesC from 2_7_0 to 3_0 trunk

J

jayway

I am a newbie at Xerces but not at C++, especialy Microsoft Visual C++.

After Googling and reading FAQs and the Xerces source code, and I am
near the end of what I can do before begging for help from the experts.
I am trying to migrate some source code (I didn't write it) from
Xerces 2.7 to the trunk version, 3.0, because I need to build in Visual
Studio 2005. My builds of XercesC and XalanC are successful, but I am
getting compiler errors building the source code I'm upgrading.

error C2039: 'setVersion' : is not a member of
'xercesc_3_0::DOMDocument'
error C2039: 'setEncoding' : is not a member of
'xercesc_3_0::DOMDocument'
error C2065: 'DOMWriter' : undeclared identifier
error C2039: 'createDOMWriter' : is not a member of
'xercesc_3_0::DOMImplementationLS'

I can confirm that none of the missing functions/classes can be found
in the current Xerces source distribution, but I am at a loss to find
any reference to their becoming deprecated. The (ugly) function I'm
trying to upgrade is attempting to take a collection of strings and
write them to an XML file on the disk. This code was stable with
Xerces 2.7. All of my other source compiles successfully in 3.0.

Many thanks for any help or advice!

--Josh--




int XMLMap::produceRecord(const CList<CString,CString>& params, const
int &nNumTokensToSkip, const CString &szFilename, Logger* logger) const
{
int tokenCount = params.GetCount() - nNumTokensToSkip;

if (GetNumberOfBlTokens() != tokenCount)
{
CString error;
error.Format("Cannot produce record: %d tokens received, but %d
expected.",
tokenCount, GetNumberOfBlTokens());
logger->LogEvent(error);
return 0;
}
CString output = "";

DOMImplementation* impl = DOMImplementation::getImplementation();

try
{
XERCES_CPP_NAMESPACE::DOMDocument* doc = impl->createDocument(
X(szBaseNamespace), // root element
namespace URI.
X(szMessageName), // root element name
0); // document type object
(DTD).

// SEt the version and encoding based on the tokens
doc->setVersion(X(szXMLVersion));
doc->setEncoding(X(szEncoding));

// Grab the root node and the first element
DOMNode* root = doc->getFirstChild();
DOMElement* rootElem= doc->getDocumentElement();

// Set the name space attributes based on the saved tokens
int iNameSpaces = 0;
for (iNameSpaces = 0; iNameSpaces < aszNameSpacesURIs.GetSize();
iNameSpaces++)
{

rootElem->setAttributeNS(X(aszNameSpacesURIs.GetAt(iNameSpaces)),
X(aszQualifiedNames.GetAt(iNameSpaces)),
X(aszNameSpaceValues.GetAt(iNameSpaces)));
}

CString szValue;
POSITION paramPos = params.GetHeadPosition();

int iToken = 0;
for (iToken = 0; iToken < nNumTokensToSkip; iToken++)
{
params.GetNext(paramPos);
}

int iMapRecord = 0;
for (iMapRecord = 0; iMapRecord < aszParameterParents.GetSize();
iMapRecord++)
{
DOMNode *current = NULL;
DOMNodeIterator* itr = doc->createNodeIterator(root,
DOMNodeFilter::SHOW_ALL, NULL, true);
for ( current = root; current != 0; current = itr->nextNode()
)
{
CString nodeName =
XMLString::transcode(current->getNodeName());
if (X(aszParameterParents.GetAt(iMapRecord)) == X(nodeName)
)
{
// new attribute
if (aszParameterTypes.GetAt(iMapRecord) ==
ATTRIBUTE_TYPE)
{
if (aszLiteralValues.GetAt(iMapRecord) == "")
{
szValue = params.GetAt(paramPos);
params.GetNext(paramPos);
}
else
{
szValue = aszLiteralValues.GetAt(iMapRecord);

if (szValue == SKIP_TOKEN)
{
szValue = "";
}
}

// Only add the attribute if we are actually
assigning a value
if (szValue != "")
{
DOMAttr* newAttrib =
doc->createAttribute(X(aszParameterNames.GetAt(iMapRecord)));
newAttrib->setNodeValue(X(szValue));
if (current->getNodeType() ==
DOMNode::ELEMENT_NODE)
{

((DOMElement*)current)->setAttributeNode(newAttrib);
break;
}
}
}
// new element
else if (aszParameterTypes.GetAt(iMapRecord) ==
ELEMENT_TYPE)
{
DOMElement* newElement =
doc->createElement(X(aszParameterNames.GetAt(iMapRecord)));
current->appendChild(newElement);
break;
}
}
}
}
DOMWriter *theSerializer =
((DOMImplementationLS*)impl)->createDOMWriter();
theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
TRUE);
XMLFormatTarget *myFormTarget;
myFormTarget = new LocalFileFormatTarget(szFilename);
theSerializer->writeNode(myFormTarget, *doc);

delete theSerializer;
delete myFormTarget;
doc->release();
return 1;
}
catch (DOMException e)
{
CString szResponse = CString("Error assembling xml request: ") +
XMLString::transcode(e.msg);
logger->LogEvent(szResponse);
return 0;
}
}
 
M

Marco De Paoli

I am a newbie at Xerces but not at C++, especialy Microsoft Visual C++.

After Googling and reading FAQs and the Xerces source code, and I am
near the end of what I can do before begging for help from the experts.
I am trying to migrate some source code (I didn't write it) from
Xerces 2.7 to the trunk version, 3.0, because I need to build in Visual
Studio 2005. My builds of XercesC and XalanC are successful, but I am
getting compiler errors building the source code I'm upgrading.

error C2039: 'setVersion' : is not a member of
'xercesc_3_0::DOMDocument'
error C2039: 'setEncoding' : is not a member of
'xercesc_3_0::DOMDocument'
error C2065: 'DOMWriter' : undeclared identifier
error C2039: 'createDOMWriter' : is not a member of
'xercesc_3_0::DOMImplementationLS'

I can confirm that none of the missing functions/classes can be found
in the current Xerces source distribution, but I am at a loss to find
any reference to their becoming deprecated. The (ugly) function I'm
trying to upgrade is attempting to take a collection of strings and
write them to an XML file on the disk. This code was stable with
Xerces 2.7. All of my other source compiles successfully in 3.0.

Many thanks for any help or advice!

--Josh--




int XMLMap::produceRecord(const CList<CString,CString>& params, const
int &nNumTokensToSkip, const CString &szFilename, Logger* logger) const
{
int tokenCount = params.GetCount() - nNumTokensToSkip;

if (GetNumberOfBlTokens() != tokenCount)
{
CString error;
error.Format("Cannot produce record: %d tokens received, but %d
expected.",
tokenCount, GetNumberOfBlTokens());
logger->LogEvent(error);
return 0;
}
CString output = "";

DOMImplementation* impl = DOMImplementation::getImplementation();

try
{
XERCES_CPP_NAMESPACE::DOMDocument* doc = impl->createDocument(
X(szBaseNamespace), // root element
namespace URI.
X(szMessageName), // root element name
0); // document type object
(DTD).

// SEt the version and encoding based on the tokens
doc->setVersion(X(szXMLVersion));
doc->setEncoding(X(szEncoding));

// Grab the root node and the first element
DOMNode* root = doc->getFirstChild();
DOMElement* rootElem= doc->getDocumentElement();

// Set the name space attributes based on the saved tokens
int iNameSpaces = 0;
for (iNameSpaces = 0; iNameSpaces < aszNameSpacesURIs.GetSize();
iNameSpaces++)
{

rootElem->setAttributeNS(X(aszNameSpacesURIs.GetAt(iNameSpaces)),
X(aszQualifiedNames.GetAt(iNameSpaces)),
X(aszNameSpaceValues.GetAt(iNameSpaces)));
}

CString szValue;
POSITION paramPos = params.GetHeadPosition();

int iToken = 0;
for (iToken = 0; iToken < nNumTokensToSkip; iToken++)
{
params.GetNext(paramPos);
}

int iMapRecord = 0;
for (iMapRecord = 0; iMapRecord < aszParameterParents.GetSize();
iMapRecord++)
{
DOMNode *current = NULL;
DOMNodeIterator* itr = doc->createNodeIterator(root,
DOMNodeFilter::SHOW_ALL, NULL, true);
for ( current = root; current != 0; current = itr->nextNode()
)
{
CString nodeName =
XMLString::transcode(current->getNodeName());
if (X(aszParameterParents.GetAt(iMapRecord)) == X(nodeName)
)
{
// new attribute
if (aszParameterTypes.GetAt(iMapRecord) ==
ATTRIBUTE_TYPE)
{
if (aszLiteralValues.GetAt(iMapRecord) == "")
{
szValue = params.GetAt(paramPos);
params.GetNext(paramPos);
}
else
{
szValue = aszLiteralValues.GetAt(iMapRecord);

if (szValue == SKIP_TOKEN)
{
szValue = "";
}
}

// Only add the attribute if we are actually
assigning a value
if (szValue != "")
{
DOMAttr* newAttrib =
doc->createAttribute(X(aszParameterNames.GetAt(iMapRecord)));
newAttrib->setNodeValue(X(szValue));
if (current->getNodeType() ==
DOMNode::ELEMENT_NODE)
{

((DOMElement*)current)->setAttributeNode(newAttrib);
break;
}
}
}
// new element
else if (aszParameterTypes.GetAt(iMapRecord) ==
ELEMENT_TYPE)
{
DOMElement* newElement =
doc->createElement(X(aszParameterNames.GetAt(iMapRecord)));
current->appendChild(newElement);
break;
}
}
}
}
DOMWriter *theSerializer =
((DOMImplementationLS*)impl)->createDOMWriter();
theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
TRUE);
XMLFormatTarget *myFormTarget;
myFormTarget = new LocalFileFormatTarget(szFilename);
theSerializer->writeNode(myFormTarget, *doc);

delete theSerializer;
delete myFormTarget;
doc->release();
return 1;
}
catch (DOMException e)
{
CString szResponse = CString("Error assembling xml request: ") +
XMLString::transcode(e.msg);
logger->LogEvent(szResponse);
return 0;
}
}

I have exactly the same problem.
Any solution would be appreciated!
Marco

BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top