使用vb 6.0

时间:2015-06-25 16:02:11

标签: xml vb6 parent-child

此源代码生成一个XML,每个新节点都附加到根,我想要嵌套节点。

重新添加子节点的信息Ver 1A 6/24/15-下一个示例代码5/29/15

Private Sub Form_Load()     Dim dom,node,attr

On Error GoTo ErrorHandler

Set dom = CreateDOM


Set node = Nothing

' Create a comment for the document.
Set node = dom.createComment("sample xml file NEED A CHILD AND SUB CHILD.")
dom.appendChild node
Set node = Nothing

' Create the root element.
Dim root
Set root = dom.createElement("ReturnState")

' Create a "created" attribute for the root element and
' assign the "using dom" character data as the attribute value.
Set attr = dom.createAttribute("stateSchemaVersion")
attr.Value = "FSETV5.0"
root.setAttributeNode attr
Set attr = Nothing

' Add the root element to the DOM instance.
dom.appendChild root
' Insert a newline + tab.
root.appendChild dom.createTextNode(vbNewLine)
' Create and add more nodes to the root element just created.
' Create a text element.
Set node = dom.createElement("SubmissionID")
node.Text = "1026132015623SUBID"
' Add text node to the root element.
root.appendChild node
Set node = Nothing
  ' Add a newline plus tab.
root.appendChild dom.createTextNode(vbTab)

' Create an element 
Set node = dom.createElement("ReturnHeaderState")


Set node1 = dom.createElement("Jurisdiction")
node1.Text = "NYS"
' Add text node to the root element.
node.appendChild node1
Set node1 = Nothing

Set node1 = dom.createElement("TimeStamp")
node1.Text = "2013-24-06"
' Add text node to the root element.
node.appendChild node1
Set node1 = Nothing

Rem ------------下一个varable     '创建一个元素     设置node2 = dom.createElement(“PaidPreparerInformation”)     'node.appendChild node2:'6/23/15

Set node1 = dom.createElement("DateSigned")
node1.Text = "June 23 2015"
' Add text node to the root element.
node2.appendChild node1
Set node1 = Nothing

Set node1 = dom.createElement("TimeStamp")
node1.Text = "2013-24-06:12:36.23"
' Add text node to the root element.
node2.appendChild node1

dom.documentElement.appendChild node2

Set node2 = Nothing


Rem---replaced after sec node
dom.documentElement.appendChild node
''Set node = Nothing


Rem-removed because of line above

''dom.documentElement.appendChild node1     设置节点=无       '添加换行符加选项卡。     root.appendChild dom.createTextNode(vbNewLine + vbTab)

Rem ------------结束下一个vara

' Create an element to hold three empty subelements.
Set node = dom.createElement("node3")

' Create a document fragment to be added to node3.
Set frag = dom.createDocumentFragment
    ' Add a newline + tab + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
frag.appendChild dom.createElement("subNode1")
   ' Add a newline + tab + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
frag.appendChild dom.createElement("subNode2")
   ' Add a newline + tab + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
frag.appendChild dom.createElement("subNode3")
   ' Add a newline + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab)
node.appendChild frag
Set frag = Nothing

root.appendChild node
   ' Add a newline.
root.appendChild dom.createTextNode(vbNewLine)
Set node = Nothing

' Save the XML document to a file.
dom.save App.Path + "\TestForChild.xml"
Set root = Nothing
Set dom = Nothing
Exit Sub

的ErrorHandler:     MsgBox Err.Description 结束子

rem ----这是我的源代码生成的

enter code here - 在此输入代码< / code> - >               -
              1026132015623SUBID              -               2015年6月23日              2013-24-06:12:36.23                           -              NYS              2013-24-06                           -                                                                    

       REM---------this is what I want

       rem   I want the ReturnHeaderState to have children with additonal     nodes
       rem   like PaidPreparerInformation, Which has addtional nodes like date, name,
       rem   address not off the root.  I want them inside the ReturnHeaderState node.





       - <!-- sample xml file NEED A CHILD AND SUB CHILD.
        --> 
       - <ReturnState stateSchemaVersion="FSETV5.0">

         <SubmissionID>1026132015623SUBID</SubmissionID> 

       - <ReturnHeaderState>
         <Jurisdiction>NYS</Jurisdiction> 
         <TimeStamp>2013-24-06</TimeStamp> 

      - <PaidPreparerInformation>
        <DateSigned>June 23 2015</DateSigned> 
        <TimeStamp>2013-24-06:12:36.23</TimeStamp> 
        </PaidPreparerInformation>


      - <node3>
        <subNode1 /> 
        <subNode2 /> 
        <subNode3 /> 
        </node3>

        </ReturnHeaderState>

        </ReturnState>









       <ReturnHeaderState>
       <Jurisdication>NYS</Jurisdication>
       <TimeStamp>2015-06</TimeStamp>
       <PaidPreInfo>

0 个答案:

没有答案