Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can I recursively read in an XML Schema(including user-defined types) with VB?

Posted on 2003-11-24
4
Medium Priority
?
424 Views
Last Modified: 2013-11-19
I'm re-writing a tool of ours that reads in XML Schemas, and generates XML instances of them. The original one was hard-coded to read in only certain schemas, and there are no situations with user-defined schema types like:
<xs:element name="dataPoint1" type="dataPoint" minOccurs="0"/>

The thing is, I need to re-write it to be more general, to take in any schema if possible, so the updated version will need to:

1) Read in the XSD, and save it into a node list(done).
2) Parse through the list, and trigger a flag if the current node is of a user-defined type(done).
3) Recursively go back through the list & replace the given node with the complexType information that defines it.(???)

Still relatively new to VB, and I'm having trouble coming up with the right syntax for recursive functions in VB.

Suggestions anyone? Even some examples for recursion with xml node lists would be helpful.

Thanks!
0
Comment
Question by:Inward_Spiral
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
ashoooo earned 1000 total points
ID: 9813303
Try using the MSXML library for vb6

As for the recusive functions, here is an idea how to go about it.

Private Sub LoadXMLIntoTree()
    Dim xmlDoc As MSXML2.DOMDocument
    Dim xmlNode As IXMLDOMNode
    Dim n as Node

    Set xmlDoc = New DOMDocument
   
    xmlDoc.async = False
    xmlDoc.Load "somefile.xml"

    Set xmlNode = xmlDoc

   ' get the root node using the MSXML object

    If Not xmlDoc.childNodes(0).baseName = "xml" Then        ' change this to your own root node
        MsgBox "Error in configuration file"
    End If
   
   ' add the first node to the tree view
   set n = treeview1.Nodes.add (,,GetXMLNodeAttribute(xmlChildNodes(0), "name")

   ' call the recursive function on this node

   LoadNode n, xmlDoc.childNodes(0)
End Sub

Private Sub LoadNode(n as Node, x as IXMLDomNode)
    Dim nChild as Node
    Dim xmlChildNode as IXMLDOMNode

    For Each xmlChildNode In x.childNodes(0).childNodes
        strAttrValue = GetXMLNodeAttribute(xmlProjectNode, "name")
        If Not strAttrValue = vbNullString Then
            Set nChild = treeview1.Nodes.Add (tvwchild, n, strAttrValue) ' create a new child

            ' now call this function on the new node and xml node
            LoadNode nChild, xmlChildNode
        End If
    Next xmlChildNode
End Sub


Public Function GetXMLNodeAttribute(ByVal xmlNode As IXMLDOMNode, ByVal attrName As String) As String
    Dim strAttrValue As String
    Dim xmlAttr As IXMLDOMAttribute
   
    On Error GoTo errHandler
    For Each xmlAttr In xmlNode.Attributes
        If xmlAttr.baseName = attrName Then
            GetXMLNodeAttribute = xmlAttr.Value
            Exit Function
        End If
    Next xmlAttr
   
    GetXMLNodeAttribute = vbNullString
   
errHandler:
    Set xmlAttr = Nothing
    Exit Function
End Function


Hope this helps...
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9813316
I copied and pasted the code from one of my apps.. so please change all instances of xmlProjectNode to xmlChildNode
0
 

Author Comment

by:Inward_Spiral
ID: 9972731
Crap, I got it working and never awarded points.

Sorry, didn't mean to pull a scrooge!
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9972798
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question