怎样读取下面的XML文件,生成一SQL语句,

netty 2003-05-06 06:26:33
注意:是先提取出节点名字,生成一新表,然后再把数据导入到表中.
我用的是VB,MS XML DOM3.0

XML文件很简单

<?xml version="1.0" ?>
<xml>
<row><Code>001</Code><Name>Huahua</Name><Sex>F</Sex><Age>21</Age></row>
<row><Code>002</Code><Name>Panzi</Name><Sex>F</Sex><Age>10</Age></row>
<row><Code>003</Code><Name>Xiaogou</Name><Sex>M</Sex><Age>5</Age></row>
</xml>

...全文
41 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lifejoy 2003-05-07
  • 打赏
  • 举报
回复
贝贝!E章给的东西是正确运行的,你只要简单改造一下就可以取得你需要的功能
ssm1226 2003-05-07
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim xmldoc As New MSXML2.DOMDocument
xmldoc.Load "test.xml"

Set nodes = xmldoc.selectNodes("//row")

For Each node In nodes
StrT = "节点名称:" & node.nodeName
For Each subnode In node.childNodes
StrT = StrT & "子节点名称:" & subnode.nodeName
Next
Next

MsgBox StrT
End Sub
netty 2003-05-06
  • 打赏
  • 举报
回复
To : net_lover(孟子E章) :
谢谢了

但是我要首先读出“Row”元素和“Code,Name,Sex,Age”元素,怎么读阿?

孟子E章 2003-05-06
  • 打赏
  • 举报
回复
Set nodes =xmldom.selectNodes("//row")
for each node in nodes
sql = "insert into tbl (code,name,sex,age) values('"& node.selectSingleNode("Code").text &"','"& node.selectSingleNode("Name").text &"','"& node.selectSingleNode("Sex").text &"','"& node.selectSingleNode("Age").text &"')"
cn.execute sql
Next
netty 2003-05-06
  • 打赏
  • 举报
回复
看来人都走了

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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