Newbie problems migrating XercesC from 2_7_0 to 3_0 trunk

Discussion in 'XML' started by jayway@myrealbox.com, Jan 9, 2007.

  1. Guest

    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;
    }
    }
     
    , Jan 9, 2007
    #1
    1. Advertising


  2. > 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
     
    Marco De Paoli, Feb 12, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Thiele

    Readline on OS X for trunk build

    James Thiele, Oct 28, 2007, in forum: Python
    Replies:
    0
    Views:
    294
    James Thiele
    Oct 28, 2007
  2. Bo Schwarzstein

    how to release file handle in xercesc

    Bo Schwarzstein, Dec 1, 2008, in forum: XML
    Replies:
    1
    Views:
    448
    Bo Schwarzstein
    Dec 4, 2008
  3. Andy
    Replies:
    2
    Views:
    217
  4. Skip Montanaro
    Replies:
    2
    Views:
    326
    88888 Dihedral
    Oct 7, 2012
  5. Ned Deily
    Replies:
    0
    Views:
    178
    Ned Deily
    Oct 6, 2012
Loading...

Share This Page