Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Newbie problems migrating XercesC from 2_7_0 to 3_0 trunk

Reply
Thread Tools

Newbie problems migrating XercesC from 2_7_0 to 3_0 trunk

 
 
jayway@myrealbox.com
Guest
Posts: n/a
 
      01-09-2007
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:OMDocument'
error C2039: 'setEncoding' : is not a member of
'xercesc_3_0:OMDocument'
error C2065: 'DOMWriter' : undeclared identifier
error C2039: 'createDOMWriter' : is not a member of
'xercesc_3_0:OMImplementationLS'

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:roduceRecord(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:OMDocument* 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(iNameSpa ces)),
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(iMapRec ord)));
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(iMapRecor d)));
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;
}
}

 
Reply With Quote
 
 
 
 
Marco De Paoli
Guest
Posts: n/a
 
      02-12-2007

> 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:OMDocument'
> error C2039: 'setEncoding' : is not a member of
> 'xercesc_3_0:OMDocument'
> error C2065: 'DOMWriter' : undeclared identifier
> error C2039: 'createDOMWriter' : is not a member of
> 'xercesc_3_0:OMImplementationLS'
>
> 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:roduceRecord(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:OMDocument* 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(iNameSpa ces)),
> 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(iMapRec ord)));
> 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(iMapRecor d)));
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems building Python from hg trunk on Open SUSE Skip Montanaro Python 2 10-07-2012 05:01 PM
Re: Problems building Python from hg trunk on Open SUSE Ned Deily Python 0 10-06-2012 01:37 AM
how to release file handle in xercesc Bo Schwarzstein XML 1 12-04-2008 12:29 PM
Newbie question...configure core port as a trunk or as a vlan member? Ned Cisco 4 07-28-2006 10:09 PM
Newbie question: migrating "global variables" from ASP to ASP.NET =?Utf-8?B?QW5kcmVhcyBIb2ZtYW5u?= ASP .Net 2 04-18-2005 01:53 PM



Advertisments