-- 作者:yingsunyunmeng
-- 发布时间:12/4/2011 11:06:00 AM
--
#import <msxml4.dll> #include <string> #include <list> #include <objbase.h> using namespace MSXML2; CoInitialize(NULL); //初始化COM库 HRESULT hr; MSXML2::IXMLDOMDocument2Ptr ptrFedDocument=NULL; //指向整个FED文件的指针 MSXML2::IXMLDOMElementPtr ptrElement=NULL; MSXML2::IXMLDOMNodePtr ptrRootNode=NULL; //整个文件的根节点 hr=ptrFedDocument.CreateInstance(__uuidof(DOMDocument40));//创建MSXML文档实例 if(FAILED(hr)) { CoUninitialize(); throw FSLLRC_CreateMSXMLInstanceException(); } ptrFedDocument->async = VARIANT_FALSE; hr=ptrFedDocument->load(fedFileName.c_str()); //加载FED文件 if(FAILED(hr)) { CoUninitialize(); throw FSLLRC_LoadFEDException(); } ptrElement=ptrFedDocument->GetdocumentElement(); ptrRootNode=ptrFedDocument->selectSingleNode(_bstr_t("FSLRTIFED")); if(NULL==ptrRootNode) { BSTR reason; ptrFedDocument->parseError->get_reason(&reason); system("pause"); } if(NULL==ptrRootNode) { if(ptrFedDocument!=NULL) { ptrFedDocument.Release(); } if(ptrElement!=NULL) { ptrElement.Release(); } CoUninitialize(); throw FSLLRC_FEDDetialException("FED文件根节点为空"); } if(ptrFedDocument!=NULL) { ptrFedDocument.Release(); } if(ptrElement!=NULL) { ptrElement.Release(); } if(ptrRootNode!=NULL) { ptrRootNode.Release(); } CoUninitialize(); 这是程序中解析部分的代码, <?xml version="1.0" encoding="UTF-8"?> <!--FED file template--> <FSLRTIFED> <Federation/> <Fedversion/> <spaces/> <ObjectRoot name="FSLRTIObjectRoot"> <Object name="Plan"> <attribute name="PositionX" TransportationType="Reliable" TransportationOrder="TimeStamp"/> <attribute name="PositionY" TransportationType="Reliable" TransportationOrder="TimeStamp"/> <attribute name="PositionZ" TransportationType="Reliable" TransportationOrder="TimeStamp"/> <Object name="K-8"> <attribute name="K-8-Color" TransportationType="Reliable" TransportationOrder="TimeStamp"/> <Object name="K-8-2"> <attribute name="K-8-2-Speed" TransportationType="BestEffort" TransportationOrder="TimeStamp"/> <attribute name="K-8-2-Acceleration" TransportationType="BestEffort" TransportationOrder="TimeStamp"/> </Object> </Object> </Object> </ObjectRoot> <InteractionRoot name="Bing" TransportationType="Reliable" TransportationOrder="ReceiveOrder"> <parameter name="BoulNum"/> <parameter name="DX"/> <parameter name="DY"/> </InteractionRoot> </FSLRTIFED> 这是XML文件
|