Results 1 to 3 of 3

Thread: simple problem creating XML files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    simple problem creating XML files

    hi, I am trying to make an xml file where the first element is called "NEWAPPOINTMENTS" then the next is called "APPOINTMENT" then within APPOINTMENT info such as "START" "END" "SUBJECT" so far I have attempted this using the following code:

    VB Code:
    1. Set objDOM = New DOMDocument
    2.                
    3.                 objDOM.preserveWhiteSpace = True
    4.                 Set objRow = objDOM.createElement("NEWAPPOINTMENTS")
    5.                 objDOM.appendChild objRow
    6.                    
    7.                 Set objField = objDOM.createElement("APPOINTMENT")
    8.                 objRow.appendChild objField
    9.  
    10.                 Set objField = objDOM.createElement("START")
    11.                 objField.nodeTypedValue = oItem.Start
    12.                 objRow.appendChild objField
    13.        
    14.              
    15.                 Set objField = objDOM.createElement("END")
    16.                 objField.nodeTypedValue = oItem.End
    17.                 objRow.appendChild objField
    18.        
    19.              
    20.                 Set objField = objDOM.createElement("SUBJECT")
    21.                 'objField.dataType = "dateTime"
    22.                 objField.nodeTypedValue = oItem.Subject
    23.                 objRow.appendChild objField


    this creates me an xml file but dosent put the start, end and subject within the Appointment element, and if i try to make the APPOINTMENT element as appendChild.objRow then i get an error "only one top lvl element allowed"

    many thanks for any help

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: simple problem creating XML files

    Here is a quick sample creating 2 appointment nodes with details
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim xmlDoc As MSXML2.DOMDocument
    3. Dim objRoot As MSXML2.IXMLDOMNode
    4. Dim objChild As MSXML2.IXMLDOMNode
    5. Dim objDetails As MSXML2.IXMLDOMNode
    6. Dim objProcInst As MSXML2.IXMLDOMProcessingInstruction
    7.  
    8.     'Create an XML document
    9. '    Set xmlDoc = CreateObject("Microsoft.XMLDOM")
    10.     Set xmlDoc = New MSXML2.DOMDocument
    11.    
    12.    
    13.     'Create a root element and append it to the document
    14.     Set objRoot = xmlDoc.createElement("NEWAPPOINTMENTS")
    15.     xmlDoc.appendChild objRoot
    16.    
    17.     'Create node for first appointment
    18.     Set objChild = xmlDoc.createElement("APPOINTMENT")
    19.     objRoot.appendChild objChild
    20.    
    21.     'Add the details for first appointment
    22.     Set objDetails = xmlDoc.createElement("START")
    23.     objDetails.Text = "Code to fill start text node"
    24.     objChild.appendChild objDetails
    25.    
    26.     Set objDetails = xmlDoc.createElement("END")
    27.     objDetails.Text = "Code to fill start end node"
    28.     objChild.appendChild objDetails
    29.    
    30.     Set objDetails = xmlDoc.createElement("SUBJECT")
    31.     objDetails.Text = "Code to fill start subject node"
    32.     objChild.appendChild objDetails
    33.    
    34.     'Create node for second appointment
    35.     Set objChild = xmlDoc.createElement("APPOINTMENT")
    36.     objRoot.appendChild objChild
    37.    
    38.     'Add the details for second appointment
    39.     Set objDetails = xmlDoc.createElement("START")
    40.     objDetails.Text = "Code to fill second appointment start text node"
    41.     objChild.appendChild objDetails
    42.    
    43.     Set objDetails = xmlDoc.createElement("END")
    44.     objDetails.Text = "Code to fill second appointment end node"
    45.     objChild.appendChild objDetails
    46.    
    47.     Set objDetails = xmlDoc.createElement("SUBJECT")
    48.     objDetails.Text = "Code to fill second appointment subject node"
    49.     objChild.appendChild objDetails
    50.    
    51.     'Add an XML processing instruction
    52.     'and insert it before the root element
    53.     Set objProcInst = xmlDoc.createProcessingInstruction("xml", "version='1.0'")
    54.     xmlDoc.insertBefore objProcInst, xmlDoc.childNodes(0)
    55.    
    56.     'Save the XML file to the c directory
    57.     xmlDoc.save "c:\test.xml"
    58. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: simple problem creating XML files

    thanks ive managed to sort that stuff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width