在Windows上用Xerces 3.0.1和C编写XML
发布时间:2020-12-13 20:40:50 所属栏目:Windows 来源:网络整理
导读:我有使用Xerces 3.0.1创建XML文件的以下函数,如果我使用filePath“foo.xml”或“../foo.xml”调用此函数,它工作得很好,但如果我传入“c:/foo.xml”然后我在这一行得到一个例外 XMLFormatTarget *formatTarget = new LocalFileFormatTarget(targetPath); 有
我有使用Xerces 3.0.1创建XML文件的以下函数,如果我使用filePath“foo.xml”或“../foo.xml”调用此函数,它工作得很好,但如果我传入“c:/foo.xml”然后我在这一行得到一个例外
XMLFormatTarget *formatTarget = new LocalFileFormatTarget(targetPath); 有人可以解释为什么我的代码适用于相对路径,但不是绝对路径吗? 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("rn")); // 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(); }
你在使用Windows Vista吗?也许你没有必要的权限?
看到这个问题: Exception in two line Xerces program (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 读取Internet Explorer保护模式注册表
- windows-server-2008 – 在Active Directory中禁用密码复杂
- windows-server-2003 – 我想替换现有的域控制器,但保留AD等
- windows – cygwin curl,Wget,wget和top“命令未找到”
- 订阅到期后,MSDN Windows许可证仍然可以正常工作吗?
- windows-8 – 为Xbox One开发应用程序?
- 为什么Bonjour for Windows没有看到我的IPv6专用Linux主机?
- 禁用win7更新
- microsoft-graph – 使用所有者在Microsoft Graph API中创建
- 是否可以防止.NET MSIL DLL的反编译?
推荐文章
站长推荐
- Windows及Android倍速播放视频软件下载
- winapi – Windows API中有哪些定期计时器对象?
- 安装 – 使用InstallUtil安装.NET Windows服务时
- windows – MINIDUMP_TYPE枚举值的哪些组合将为我
- windows-xp – 如何强制某些应用程序使用特定的网
- windows-7 – 注册表设置EnableLinkedConnection
- 用自定义驱动程序替换Windows USB类驱动程序?
- Windows:具有重定向输入和输出的子进程
- Windows Server 2012 R2 WSUS-6:配置计算机组和
- windows-server-2008-r2 – 将Ctrl-Alt-Del发送到
热点阅读