l'écriture d'un document XML avec Xerces 3.0.1 et C++ sur windows

j'ai la fonction suivante que j'ai écrit pour créer un fichier XML à l'aide de Xerces 3.0.1, si j'appelle cette fonction avec un chemin d'accès de l' "foo.xml" ou "../foo.xml" il fonctionne très bien, mais si je passe en "c:/foo.xml" puis-je obtenir une exception sur cette ligne

XMLFormatTarget *formatTarget = new LocalFileFormatTarget(targetPath);

quelqu'un peut m'expliquer pourquoi mon code fonctionne pour les chemins relatifs, mais pas les chemins d'accès absolus s'il vous plaît?
merci beaucoup.

const int ABSOLUTE_PATH_FILENAME_PREFIX_SIZE = 9;

void OutputXML(xercesc::DOMDocument* pmyDOMDocument, std::string filePath)
{
    //Return the first registered implementation that has the desired features. In this case, we are after a DOM implementation that has the LS feature... or Load/Save.
    DOMImplementation *implementation = DOMImplementationRegistry::getDOMImplementation(L"LS");

    //Create a DOMLSSerializer which is used to serialize a DOM tree into an XML document.
    DOMLSSerializer *serializer = ((DOMImplementationLS*)implementation)->createLSSerializer();

    //Make the output more human readable by inserting line feeds.
    if (serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
        serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);

    //The end-of-line sequence of characters to be used in the XML being written out. 
    serializer->setNewLine(XMLString::transcode("\r\n")); 

    //Convert the path into Xerces compatible XMLCh*.
    XMLCh *tempFilePath = XMLString::transcode(filePath.c_str());

    //Calculate the length of the string.
    const int pathLen = XMLString::stringLen(tempFilePath);

    //Allocate memory for a Xerces string sufficent to hold the path.
    XMLCh *targetPath = (XMLCh*)XMLPlatformUtils::fgMemoryManager->allocate((pathLen + ABSOLUTE_PATH_FILENAME_PREFIX_SIZE) * sizeof(XMLCh));

    //Fixes a platform dependent absolute path filename to standard URI form.
    XMLString::fixURI(tempFilePath, targetPath);

    //Specify the target for the XML output.
    XMLFormatTarget *formatTarget = new LocalFileFormatTarget(targetPath);
    //XMLFormatTarget *myFormTarget = new StdOutFormatTarget();

    //Create a new empty output destination object.
    DOMLSOutput *output = ((DOMImplementationLS*)implementation)->createLSOutput();

    //Set the stream to our target.
    output->setByteStream(formatTarget);

    //Write the serialized output to the destination.
    serializer->write(pmyDOMDocument, output);

    //Cleanup.
    serializer->release();
    XMLString::release(&tempFilePath);
    delete formatTarget;
    output->release();
}
+1 car j'ai le même problème. Je ne pense pas que la réponse que vous avez choisi comme correcte résout le problème mais comme je ne les autorisations nécessaires (même emplacement de fichier pour à la fois relative et absolue des chemins, des travaux relatifs, absolus qui ne marche pas). Comment avez-vous résolu votre problème???
Je suis sûr que c'était un problème d'autorisations pour moi, si je me souviens bien, j'étais en train d'écrire à la racine du disque C sous Vista, et il ne me laisserait pas.
Merci Jon. Je pense que vous devez avoir raison. J'ai corrigé quelques autres questions dans ma xerces wrapper et maintenant il fonctionne à la fois absolue et relative. Et avec à la fois des " / " et "\ \ ' annuaire des séparateurs 🙂

OriginalL'auteur dangerousdave | 2010-05-24