zoukankan      html  css  js  c++  java
  • vb6里面生成xml文件

    终于找到了一段在我的电脑vb6+win7上能正常工作的代码。

    先添加 引用 Microsoft xml 6.0

    代码
    Dim xmlDOMDocument As DOMDocument 'xml文档

    Dim Root_Node As IXMLDOMElement '文档的根节点
    Dim Added_Node As IXMLDOMNode '新添加的节点

    Dim Added_Element As IXMLDOMNode '新添加的元素节点
    Dim Added_Attribute As IXMLDOMNode '新添加的属性

    '生成一个XML DOMDocument对象
    Set xmlDOMDocument = New MSXML2.DOMDocument

    '生成根节点
    Set Root_Node = xmlDOMDocument.createElement("Root")
    Set xmlDOMDocument.documentElement = Root_Node

    '在此节点上添加多个属性
    Call Root_Node.setAttribute("属性", "http://www.w3.org/2001/XMLSchema")
    Call Root_Node.setAttribute("属性2", "http://www.w3.org/2001/XMLSchema-instance")
    'Call Root_Node.setAttribute("属性3", "http://www.kingdee.com/ReK3Inventory")

    '生成“父亲辈”节点添加到根节点
    Set Added_Element = xmlDOMDocument.createNode(NODE_ELEMENT, "Nodes", "")
    Added_Element.Text
    = ""
    Root_Node.appendChild Added_Element

    '''''''''''此处连续生成三个“孙子辈”节点''''''''''''''''''''''''''''''''''''
    Set Added_Node = xmlDOMDocument.createNode(NODE_ELEMENT, "Node_1", "") '
    Added_Node.Text = "this Is Node_2.Texth汉字" '
    Added_Element.appendChild Added_Node
    '
    '
    Set Added_Node = xmlDOMDocument.createNode(NODE_ELEMENT, "Node_2", "") '
    Added_Node.Text = "this is Node_3.Text" '
    Added_Element.appendChild Added_Node '
    '
    Set Added_Node = xmlDOMDocument.createNode(NODE_ELEMENT, "Node_3", "") '
    Added_Node.Text = "this is Node_4.Text" '
    Added_Element.appendChild Added_Node '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '创建节点有个一般性规律: '
    '语法上体现为 父节点.appendChild 子节点       '
    '注意:父节点和子节点要声明为 IXMLDOMNode或者IXMLDOMElement '
    ' '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    '创建序言部分
    Dim pi As IXMLDOMProcessingInstruction
    Set pi = xmlDOMDocument.createProcessingInstruction("xml", "version='1.0' encoding='gb2312'")
    Call xmlDOMDocument.insertBefore(pi, xmlDOMDocument.childNodes(0))
    '直接保存成文件即可
    xmlDOMDocument.save m_AppPath & "myTest.xml"
  • 相关阅读:
    GX转账站点无法访问的问题

    .NET易忘备留 ORACLE存储过程调用
    Oracle 字符串函数
    Oracle 数值函数
    AJAX.JSONP 跨域
    机器人部署的注意事项
    IE6、7绝对定位层被遮挡的原因(主要是父层决定的)
    Oracle 新手问答
    字符设备驱动范例
  • 原文地址:https://www.cnblogs.com/mitang/p/1853308.html
Copyright © 2011-2022 走看看