xml文件是怎么解析的啊

tht228 2010-02-22 09:15:08
<?xml version="1.0" encoding="utf-8" ?>
- <Maps>
- <Map xmlns="http://www.semi.org" SubstrateId="695823901F1" SubstrateType="Wafer" FormatRevision="SEMI G85-0703">
- <Device Rows="36" LotId="6958239.013" BinType="ASCII" Columns="38" MapType="Array" NullBin="0" ProductId="K25A" WaferSize="200" CreateDate="20091106130620353" DeviceSizeX="5082.95000" DeviceSizeY="5262.95000" Orientation="0" SupplierName="Micron Technology, Inc." OriginLocation="2" MicronLotId="6958239.013">
<ReferenceDevice ReferenceDeviceX="27" ReferenceDeviceY="35" />
<Bin BinCode="G" BinCount="906" BinQuality="Pass" />
<Bin BinCode="X" BinCount="170" BinQuality="Fail" />
- <Data>
- <Row>
- <![CDATA[ 00000000000000XXGXGGGGXX00000000000000
]]>
</Row>
- <Row>
- <![CDATA[ 00000000000XXXGGGGGGXGGGGXX00000000000
]]>
</Row>
- <Row>
- <![CDATA[ 000000000XXGGGGGXGGGGGGGGGGXX000000000
]]>
</Row>
- <Row>
- <![CDATA[ 00000000XXGGGGGGGGXGGGGGGXGGGX00000000
]]>
</Row>
- <Row>
- <![CDATA[ 0000000XXGGGGGGGGGGGGGGGGGGGGGX0000000
]]>
</Row>
- <Row>
- <![CDATA[ 00000XGXGXXGGGGGGGGGGGGGGGGGGGGXX00000
]]>
</Row>
- <Row>
- <![CDATA[ 00000GGGGXGGGGGXGGGGGGGGGGGGGGGGG00000
]]>
</Row>
- <Row>
- <![CDATA[ 0000XXGGXGGGGGGGGGGGGGGGGGGGGGGGGG0000
]]>
</Row>
- <Row>
- <![CDATA[ 0000XGGGGXGGGGGGXXGGGGGGGGXGGGGGGG0000
]]>
</Row>
- <Row>
- <![CDATA[ 00XGGGGGXGGGGGGGGGGGGGGGGXGGGGGGGGXX00
]]>
</Row>
- <Row>
- <![CDATA[ 00XGGGGGGGGGGGGGGGGGGGGGXGGGGGGGGXGG00
]]>
</Row>
- <Row>
- <![CDATA[ 0XGGGGGGGGGGGXGGGGGGGGGGGGGXGGGGGXGGX0
]]>
</Row>
- <Row>
- <![CDATA[ 0XGGGGGGGGGGGGGGGGXGGGGGGGGGGGGGGGGXX0
]]>
</Row>
- <Row>
- <![CDATA[ 0XGGGGGGGXGGGGGGGGGXXGGGGGGGGGGGGXGGG0
]]>
</Row>
- <Row>
- <![CDATA[ XGGGGXGGGGGGGXXGGGGGGGGGXGXGXGGGGGGGXX
]]>
</Row>
- <Row>
- <![CDATA[ XGGGGGGXGGXGGXGGGGGGGGGGGGGGGGGGGXGGXX
]]>
</Row>
- <Row>
- <![CDATA[ XGGGGGGGGGGGGGGGGXGGGGGGGGGGGGXGGGGGGX
]]>
</Row>
- <Row>
- <![CDATA[ XGGGGGGGGGGGGGGGGGXXGGGGGGGGGGGGGGGGGX
]]>
</Row>
- <Row>
- <![CDATA[ XGGGXGGGGGGGGGGGXGXGGGXGGGGGGGGGGXGGGX
]]>
</Row>
- <Row>
- <![CDATA[ XGGGGGGXGGGGGGGGGGGGGGGGGXGGGGGGGXGGXX
]]>
</Row>
- <Row>
- <![CDATA[ XGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGXX
]]>
</Row>
- <Row>
- <![CDATA[ XXGGGGGGGGGGGGGGGGGXGGGGGGGGGGGGGGGGXX
]]>
</Row>
- <Row>
- <![CDATA[ 0GGGGGGGXGGGXGGGXXGGGGXGGGGGGGGGGGGGG0
]]>
</Row>
- <Row>
- <![CDATA[ 0XGGGGGGGGGGGGGGGGGGGXGGGGGGGGGGGGGGX0
]]>
</Row>
- <Row>
- <![CDATA[ 0XGGGGGGGGGGGGGGGGGGGGGGGGGGGXGGGGGXX0
]]>
</Row>
- <Row>
- <![CDATA[ 00XGGGGGXGGGGGGGGGGGGGGGGGGGGGGGGGXX00
]]>
</Row>
- <Row>
- <![CDATA[ 00XXGGGGGGXGGGGGGGGXGGGGGGGGGGGGGGGX00
]]>
</Row>
- <Row>
- <![CDATA[ 0000XGGGGGXGGGGGXGGGGXGGGGGGXGGGXG0000
]]>
</Row>
- <Row>
- <![CDATA[ 0000XGGGGXGGGXXGGGGGGGGGGGGGGGGXGX0000
]]>
</Row>
- <Row>
- <![CDATA[ 0000XGXGGGGGGGGGXGGGGGGGGGGGGGGGXX0000
]]>
</Row>
- <Row>
- <![CDATA[ 00000XXGGGGGGGGGGGGGGGGGGGGXXGGGX00000
]]>
</Row>
- <Row>
- <![CDATA[ 000000XXGGGGGGGGXGXGGGGGGGGGGGXX000000
]]>
</Row>
- <Row>
- <![CDATA[ 00000000GGGGGGXGGGGGGGGGGGGGGG00000000
]]>
</Row>
- <Row>
- <![CDATA[ 000000000XGGGGGGGGGGGGGXGXGGX000000000
]]>
</Row>
- <Row>
- <![CDATA[ 00000000000XGGGGXGXGGGGGGGX00000000000
]]>
</Row>
- <Row>
- <![CDATA[ 00000000000000XGGGXXGGXX00000000000000
]]>
</Row>
</Data>
</Device>
</Map>
</Maps>

如何获得数据区的信息啊?给源代码的加分。
...全文
193 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Allen_zhang 2010-02-23
  • 打赏
  • 举报
回复
网上搜索CMarkup
很简单的
tht821 2010-02-23
  • 打赏
  • 举报
回复
CoInitialize(NULL); // 初始化COM。
CComPtr<IXMLDOMDocument> spXMLDOM;
HRESULT hr=spXMLDOM.CoCreateInstance (_uuidof(DOMDocument));
// 创建解析器实例。
VARIANT_BOOL bSuccess=false;
hr=spXMLDOM->raw_load(CComVariant("xmlfile.xml"),&bSuccess);// 装载XML文档。
CComBSTR bstrSS("Device");
CComPtr<IXMLDOMNode> spDevice;
hr=spXMLDOM->raw_selectSingleNode(bstrSS,&spDevice); //搜索"Device"。
CComQIPtr<IXMLDOMElement> spDev;
spDev=spDevice;
hr= spDev ->raw_setAttribute(CComBSTR("name"),CComVariant("改的这里"));// 设置"Device"的"name"属性。
CComPtr<IXMLDOMNode> spModelNode;
hr=spXMLDOM->raw_createNode(CComVariant(NODE_ELEMENT),CComBSTR("Model"),NULL,& spModelNode); // 创建"Model"节点。
CComPtr<IXMLDOMNode> spInsertedNode;
hr=spDevice->raw_appendChild (spModelNode,&spInsertedNode); // 添加新节点到"Device"节点下面。
CString strID="123";
hr=spInsertedNode->put_text(strID.AllocSysString());// 设置"Model"的文本。
hr=spXMLDOM->save(CComVariant("xmlfile.xml")); //保存文档。
CoUninitialize(); // 结束对COM的使用。
woyaowenzi 2010-02-22
  • 打赏
  • 举报
回复
我这里有一段乱七八糟的代码,你可以参考一下:
1. 解析XML你需要引用一个dll
#import <msxml4.dll>

typedef MSXML2::IXMLDOMDocument2Ptr LPXMLDocument;
typedef MSXML2::IXMLDOMElementPtr LPXMLElement;
typedef MSXML2::IXMLDOMNodePtr LPXMLNode;
typedef MSXML2::IXMLDOMNodeListPtr LPXMLNodeList;
typedef MSXML2::IXMLDOMAttributePtr LPXMLAttribute;

2. 读取节点,一层层往下剥。
// Root
#define ROOTNODE L"TabControl"

// +1
#define ALIGNMENT L"Alignment"

// +1
#define TABPAGENODE L"TabPage"
#define TABPAGE_INDEX L"Index"
#define TABPAGE_TEXT L"Text"

// +2
#define BUTTONSNODE L"Buttons"

// +3
#define BUTTONNODE L"Button"
#define BUTTON_NAME L"Name"
#define BUTTON_TEXT L"Text"
#define BUTTON_VISABLE L"Visible"
#define BUTTON_INDEX L"Index"

void CTabCtrlData::ReadXMLFromFile( const wstring& filename )
{
CoInitialize(NULL);
LPXMLDocument pQueueDom = NULL;
HRESULT hr = pQueueDom.CreateInstance(__uuidof(MSXML2_DOCUMENT));
if ( FAILED(hr) || (NULL == pQueueDom) )
{
CoUninitialize();
return ;
}

pQueueDom->async = VARIANT_FALSE;
if ( pQueueDom->load(filename.c_str()) )
{
LPXMLElement pRoot =pQueueDom->GetdocumentElement();

// +1: Get the Alignment Node
LPXMLElement pAlignment = pRoot->selectSingleNode(ALIGNMENT);
_bstr_t str = pAlignment->Gettext();
setAlignStatus(str.GetBSTR());
SAFE_RELEASE_IXMLDOM(pAlignment);

// +1: Get the TabPage Node
LPXMLNodeList pTabPageList = pRoot->selectNodes(TABPAGENODE);
if (pTabPageList->Getlength() > 0)
{
for (int ix = 0; ix < pTabPageList->Getlength(); ++ix)
{
LPTABPAGE lpTabPage = new TABPAGE();
LPXMLElement tempTabPage = pTabPageList->item[ix];

// +2: Get the TabPage's subNode: index
wstring strTabPageIndex = getSingleNodeStr(tempTabPage, TABPAGE_INDEX);
lpTabPage->m_uIndex = _wtoi(strTabPageIndex.c_str());

// +2: Get the TabPage's subNode: text
lpTabPage->m_strText = getSingleNodeStr(tempTabPage, TABPAGE_TEXT);

// +2: Get the TabPage's subNode: Buttons (It's a list)
LPXMLElement pBottons = tempTabPage->selectSingleNode(BUTTONSNODE);
LPXMLNodeList pBottonList = pBottons->selectNodes(BUTTONNODE);
if (pBottonList->Getlength() > 0)
{
for (int jx = 0; jx < pBottonList->Getlength(); ++jx)
{
LPBUTTON lpButton = new BUTTON();
LPXMLElement tempButton = pBottonList->item[jx];

// +3: Get the button's subNode: Name/Text/Visible/Index
lpButton->m_strName = getSingleNodeStr(tempButton, BUTTON_NAME);
lpButton->m_strText = getSingleNodeStr(tempButton, BUTTON_TEXT);

wstring tempVisible = getSingleNodeStr(tempButton, BUTTON_VISABLE);
_wcslwr_s( const_cast<wchar_t*>(tempVisible.c_str()), tempVisible.length() + 1 );
lpButton->m_bVisible = (0 == tempVisible.compare(L"true")) ? 1 : 0;

lpButton->m_uIndex = _wtoi( getSingleNodeStr(tempButton, BUTTON_INDEX).c_str() );

// Finally, add the button to tab page's inner vector
lpTabPage->m_vBtnList.push_back(lpButton);
}
}

// Finally, add the tab page to CTabCtrlData's inner vector
this->m_vTabPageList.push_back(lpTabPage);
}
}
}

SAFE_RELEASE_IXMLDOM(pQueueDom);
CoUninitialize();
}

我的XML文件基本如下:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<TabControl>
<Alignment>top</Alignment>

<TabPage>
<Index>1</Index>
<Text>AAAAA</Text>
<Buttons>
<Button>
<Name></Name>
<Text>A-content_1</Text>
<Visible>false</Visible>
<Index>1</Index>
</Button>
<Button>
<Name></Name>
<Text>A-content_2</Text>
<Index>2</Index>
<Visible>true</Visible>
</Button>
</Buttons>
</TabPage>

<TabPage>
<Index>2</Index>
<Text>BBBBB</Text>
<Buttons>
<Button>
<Name></Name>
<Text>B-content_1</Text>
<Visible>true</Visible>
<Index>1</Index>
</Button>
<Button>
<Name></Name>
<Text>B-content_2</Text>
<Visible>true</Visible>
<Index>2</Index>
</Button>
<Button>
<Name></Name>
<Text>B-content_3</Text>
<Visible>true</Visible>
<Index>3</Index>
</Button>
</Buttons>
</TabPage>
</TabControl>
白云飘飘飘 2010-02-22
  • 打赏
  • 举报
回复
使用MSXML,MSDN中有SDK。
hackwolfoscar 2010-02-22
  • 打赏
  • 举报
回复
你用VC的话,就相当费事了。

可以调用COM组件来做。
西山小月 2010-02-22
  • 打赏
  • 举报
回复
用第三方的库吧,自己写有点麻烦

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧