I have created the following class which you can use:
Obviously you will need to paste the following code into a class -

********************************************************************
Option Explicit

Public Function CreateProcessingInstruction( _
        ByVal domXML As DOMDocument30, _
        strTarget As String, _
        strdata As String) As IXMLDOMProcessingInstruction
   
   'Create processing instruction
   Set CreateProcessingInstruction = _    
                domXML.CreateProcessingInstruction _
                (strTarget, strdata)
   Call domXML.appendChild(CreateProcessingInstruction)

End Function

Public Function CreateNodeElement( _
        ByVal domXML As DOMDocument30, _
        ByVal strName As String, _
        Optional ByVal nodXmlToAppend As IXMLDOMNode, _
        Optional ByVal strNodeElementText As String = "", _
        Optional ByVal strNameSpace As String = "" _
        ) As IXMLDOMNode

   'If namespace variable is set then use CreateNode else use
   'CreateElement
   If Len(strNameSpace) > 0 Then
      Set CreateNodeElement = domXML.createNode _
                                          (NODE_ELEMENT, strName, _
                                          strNameSpace)
   Else
      Set CreateNodeElement = domXML.createElement(strName)
   End If

   'Don't set text value if it is zero length
   If Len(strNodeElementText) > 0 Then
      CreateNodeElement.Text = strNodeElementText
   End If

   'Don't append a node if nodXMLtoappend is zero length
   If nodXmlToAppend Is Nothing Then
      Call domXML.appendChild(CreateNodeElement)
   Else
      Call nodXmlToAppend.appendChild(CreateNodeElement)
   End If
   
End Function

Public Function CreateNodeAttribute( _
        ByVal domXML As DOMDocument30, _
        ByVal nodXMLIn As IXMLDOMNode, _
        strName As String, _
        Optional strNameSpaceURL As String = "", _
        Optional strAttributeText As String = "") _
        As IXMLDOMAttribute
   
   'Create a node attribute
   If Len(strNameSpaceURL) > 0 Then
      Set CreateNodeAttribute = domXML.createNode _
                                          (NODE_ATTRIBUTE, _
                                          strName, strNameSpaceURL)
   Else
      Set CreateNodeAttribute = domXML.createAttribute(strName)
   End If
   If strAttributeText <> "" Then CreateNodeAttribute.Text = _
                                          strAttributeText
   Call nodXMLIn.Attributes.setNamedItem(CreateNodeAttribute)

End Function

Public Function CreateNodeComment( _
        ByVal domXML As DOMDocument30, _
        nodXMLIn As IXMLDOMNode, _
        strValue As String) As IXMLDOMComment
   
   'Create a Comment
   Set CreateNodeComment = domXML.createComment(strValue)
   Call nodXMLIn.appendChild(CreateNodeComment)
   
End Function

Public Sub CreateNameSpaceRef(ByVal domXML As DOMDocument30, _
        ByVal strValue As String)
   
   'Create a NameSpace
   Call domXML.setProperty("SelectionNamespaces", strValue)
   
End Sub

******************************************************************

Also...


I am not sure if it will help but this sample project shows how to 
generate an xml file from a csv file -


1.  Create a reference to Microsoft xml 5.0
2.  Create the following module

*******************************************************************
Option Explicit

Type Employee
  sName As String
  sAddress As String
  sCity As String
  sState As String
  sZip As String
End Type

Sub Main()
   Dim objDOMDocument As New MSXML2.DOMDocument30
   Dim objXMLDOMNode As MSXML2.IXMLDOMNode
   Dim objXMLDOMElement As MSXML2.IXMLDOMElement
   Dim vInputLine
   Dim strInput
   Dim eEmp As Employee

   objDOMDocument.async = False

   'Create Header
   objDOMDocument.appendChild XMLHeader(objDOMDocument)
   Set objXMLDOMNode =  _
           objDOMDocument.documentElement.selectSingleNode("//Doc/")
  
   'Create Employees Node
   objXMLDOMNode.appendChild objDOMDocument.createNode _
           (1, "Employees", "")
   Set objXMLDOMNode =  _
           objDOMDocument.documentElement.selectSingleNode _   
           ("//Doc/Employees")
  
   Open "source.csv" For Input As #1
   Do While Not EOF(1)
      Line Input #1, strInput
      vInputLine = Split(strInput, ",")
      eEmp.sName = vInputLine(0)
      eEmp.sAddress = vInputLine(1)
      eEmp.sCity = vInputLine(2)
      eEmp.sState = vInputLine(3)
      eEmp.sZip = vInputLine(4)
        
      objXMLDOMNode.appendChild EmployeeNode(objDOMDocument, eEmp)
   Loop
   Close #1
     
   Kill "output.xml"
   Open "output.xml" For Append As #1
   Print #1, objDOMDocument.xml
   Close #1
  
   'Clear Objects
   Set objXMLDOMElement = Nothing
   Set objXMLDOMNode = Nothing
   Set objDOMDocument = Nothing

End Sub

Function XMLHeader(ByRef objDOMDocument As MSXML2.DOMDocument30) _
         As MSXML2.IXMLDOMNode

  Dim objXMLDOMAttribute As MSXML2.IXMLDOMAttribute
  
  Set XMLHeader = objDOMDocument.createNode(1, "Doc", "")
  
  Set objXMLDOMAttribute = objDOMDocument.createAttribute("Version") _
          objXMLDOMAttribute.Text = "1.0"
  XMLHeader.Attributes.setNamedItem objXMLDOMAttribute
  
  'Clear Objects
  Set objXMLDOMAttribute = Nothing
End Function

Function EmployeeNode(ByRef objDOMDocument As MSXML2.DOMDocument30, _
         eEmp As Employee) As MSXML2.IXMLDOMNode

  Dim objXMLDOMElement As MSXML2.IXMLDOMElement
  Dim objXMLDOMAttribute As MSXML2.IXMLDOMAttribute
  
  Set EmployeeNode = objDOMDocument.createNode(1, "Employee", "")
  
  Set objXMLDOMAttribute = objDOMDocument.createAttribute("Name")
  objXMLDOMAttribute.Text = eEmp.sName
  EmployeeNode.Attributes.setNamedItem objXMLDOMAttribute
  
  Set objXMLDOMAttribute = objDOMDocument.createAttribute("Address")
  objXMLDOMAttribute.Text = eEmp.sAddress
  EmployeeNode.Attributes.setNamedItem objXMLDOMAttribute
  
  Set objXMLDOMAttribute = objDOMDocument.createAttribute("City")
  objXMLDOMAttribute.Text = eEmp.sCity
  EmployeeNode.Attributes.setNamedItem objXMLDOMAttribute
  
  Set objXMLDOMAttribute = objDOMDocument.createAttribute("State")
  objXMLDOMAttribute.Text = eEmp.sState
  EmployeeNode.Attributes.setNamedItem objXMLDOMAttribute
  
  Set objXMLDOMAttribute = objDOMDocument.createAttribute("Zip")
  objXMLDOMAttribute.Text = eEmp.sZip
  EmployeeNode.Attributes.setNamedItem objXMLDOMAttribute
  
  'Clear Objects
  Set objXMLDOMAttribute = Nothing
  Set objXMLDOMElement = Nothing
End Function

3.  Create source.csv file as follows and place it in the same 
    directory as the project:

"John","1 Peachtree Street", "Atlanta","GA","30301"
"Mark","1 Peachtree Road", "Atlanta","GA","30302"
"Mary","1 Peachtree Corners", "Alpharetta","GA","30303"

4.  Project must startup using sub.main.  
    Output.xml will be generated if you run the project.

*******************************************************************


--- In [email protected], Fun Time <[EMAIL PROTECTED]> wrote:
> 
> Could someone please tell me how to create a generic XML parser 
using 
> VB 
> For example for this xml 
> <address> 
> <name>Jonty</name> 
> <petname>Popo</petname> 
> <address>Your house</address> 
> <tell>you tell me 12321</tell> 
> <addresstt hi="ho"> 
> <name1>Jippa</name1> 
> <tell1>9873</tell1> 
> </addresstt> 
> </address> 
> 
> how to get the output to show 
> Address 
> Name:Jonty 
> Petname:Popo 
> Address:Your house 
> Tell: you tell me 12321 
> AddressTT 
> Hi:Ho 
> Name1:Jippa 
> Tell1:9873 
> 
> 
******************************&shy;******************************&shy;
*** 
> My code at the moment is 
> Option Explicit 
> Private m_AppPath As String 
> Private Sub LoadValues() 
> Dim xml_document As DOMDocument 
> Dim values_node As IXMLDOMNode 
> Dim root As IXMLDOMElement 
> Dim child As IXMLDOMNode 
> 
>     ' Load the document. 
>     Set xml_document = New DOMDocument 
>     xml_document.Load m_AppPath & "output.xml" 
> 
>     ' If the file doesn't exist, then 
>     ' xml_document.documentElement is Nothing. 
>     If xml_document.documentElement Is Nothing Then 
>         ' The file doesn't exist. Do nothing. 
>         Exit Sub 
>     End If 
> 
>     ' Find the Values section. 
>     Set root = xml_document.documentElement 
> 
> For Each child In root.childNodes 
> 
>       Text1.Text = Text1.Text & child.nodeName & " : " & child.Text 
& 
> vbCrLf 
> 
> Next 
> End Sub 
> 
> Private Sub Form_Load() 
>     ' Get the application's startup path. 
>     m_AppPath = App.Path 
>     If Right$(m_AppPath, 1) <> "\" Then m_AppPath = m_AppPath & "\" 
> 
>     ' Load the values. 
>     LoadValues 
> End Sub 
> 
> ******************************&shy;*************************** 
> And it is giving me output 
> name : Jonty 
> petname : Popo 
> address : Your house 
> tell : you tell me 12321 
> addresstt : Jippa 9873 
> 
> As you would see..it is not reading the node names name1 and 
Tell1...Also how 
> to read attributes and values?? 
> 
> Looking forward to your help 
> 
> Thanks 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> [Non-text portions of this message have been removed]





'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [email protected]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to