Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS XML help getting past top node in vb6 HELP!!!

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
not having any luck with this at all.
this code seems to show only the top of the document.
there is a lot more at the bottom.
the child of the top, only then its done.
What am I missing?
I want to see the values of the <mm:propertyGroup name="MT-World Group"> the keys and values

I have this VB6 code
Code:
      Dim DocXml As DOMDocument50
      Set DocXml = New DOMDocument50
      Dim objXMLSearchElements As IXMLDOMSelection
      Dim objXMLSearchElement As IXMLDOMElement

      Dim nod, atrib As Object
      DocXml.Load "C:\VBSafeSource\CURRENT ACTIVITY\Document9.xml"
         For Each nod In DocXml.childNodes
            Debug.Print nod.NodeName
            
            For Each atrib In nod.Attributes
               Debug.Print "atrib.baseName " & atrib.baseName
               Debug.Print "atrib.Value " & atrib.Value
            Next
         Next
it produces this output at debug.print
Code:
xml
atrib.baseName version
atrib.Value 1.0
ClinicalDocument
atrib.baseName xmlns
atrib.Value urn:hl7-org:v3
atrib.baseName cda
atrib.Value urn:hl7-org:v3
atrib.baseName mm
atrib.Value [URL unfurl="true"]http://mmodal.com/cdaExtensions[/URL]
atrib.baseName test
atrib.Value test
atrib.baseName voc
atrib.Value urn:hl7-org:v3/voc
atrib.baseName xsi
atrib.Value [URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance[/URL]
atrib.baseName hasNormals
atrib.Value 
atrib.baseName isSplitJobs
atrib.Value
here is a the top some few lines of my XML
Code:
<?xml version="1.0"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:cda="urn:hl7-org:v3" xmlns:mm="[URL unfurl="true"]http://mmodal.com/cdaExtensions"[/URL] xmlns:test="test"
 xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] mm:hasNormals="" mm:isSplitJobs="">[red] STOPS SHOWING HERE[/RED]
	<id extension="B~ClinicalDocument_999999" root="2.16.840.1.99999.9.99.9999.999.9999.99999.9999.9.99"/>
	<code/>
	<title>General Medicine Report</title>
	<versionNumber value="5"/>
	<mm:template>
		<mm:titles>
			<mm:title code="5005" name="Past Surgical History"/>
			<mm:title code="5008" name="Family History"/>
			<mm:title code="5012" name="Review of Systems"/>
			<mm:title code="5010" name="Current Medications"/>
			<mm:title code="5011" name="Allergies"/>


<mm:propertyGroup name="MT-World Group"><mm:property key="PatientPrefix" value="" type="0"/><mm:property key="PatientGiven" value="Fred" type="0"/><mm:property key="PatientFamily" value="Flintstone" type="0"/><mm:property key="PatientSuffix" value="" type="0"/><mm:property key="SSN" value="234-02-3003" type="0"/><mm:property key="Sex" value="M" type="0"/><mm:property key="MRN" value="" type="0"/><mm:property key="BillingNum" value="19929" type="0"/><mm:property key="DocType" value="2" type="0"/><mm:property key="ServiceDT" value="10-23-2004" type="0"/><mm:property key="AdmitDate" value="10-24-2004" type="0"/><mm:property key="OperDT" value="10-25-2004" type="0"/><mm:property key="DischargeDT" value="10-26-2004" type="0"/><mm:property key="DictID" value="803" type="0"/><mm:property key="DictatorPrefix" value="" type="0"/><mm:property key="DictatorGiven" value="" type="0"/><mm:property key="DictatorFamily" value="232422" type="0"/><mm:property key="DictatorSuffix" value="" type="0"/><mm:property key="DictDate" value="10-27-2004" type="0"/><mm:property key="DictTime" value="12:34" type="0"/><mm:property key="Procedure" value="3" type="0"/><mm:property key="Accession" value="232422" type="0"/><mm:property key="PhysNums" value="2" type="0"/><mm:property key="NumCopies" value="1" type="0"/><mm:property key="ReptStatus" value="2" type="0"/><mm:property key="JobId" value="99299292" type="0"/><mm:property key="ReferName" value="Sally" type="0"/><mm:property key="Company" value="MERCY" type="0"/><mm:property key="FullXMLFileName" value="" type="0"/></mm:propertyGroup></mm:customerADT>

I want to see the values of the <mm:propertyGroup name="MT-World Group"> the keys and values
such as SSN = 234-02-3003
etc
etc
TIA

DougP, MCP, A+
 
I dont have vb6 installed anymore but it should look something like this:
Code:
For Each nod In DocXml.documentElement.childNodes

Stephan
 
Document object model is as follows:

#document > root > children of root

At the moment you're asking for all childnodes all #document, which is just root. You need to use what stephen said or:
Code:
For Each nod In DocXml.firstChild.childNodes

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Ok getting closer, I have this now, but each of these nodes has children under them
here is my code
Code:
      Dim DocXml As DOMDocument50
      Set DocXml = New DOMDocument50
      Dim objXMLSearchElements As IXMLDOMSelection
      Dim objXMLSearchElement As IXMLDOMElement

      Dim nod, atrib As Object
      DocXml.Load "C:\VBSafeSource\CURRENT ACTIVITY\Document9.xml"
         For Each nod In DocXml.childNodes
            Debug.Print nod.NodeName
            For Each atrib In DocXml.documentElement.childNodes
               Debug.Print "atrib.baseName " & atrib.baseName
               
            Next
         Next
It appears from other examples I’ve seen that they are calling a recursive function inside it self if there are more that one child.
Ok now I have this from the debug.print (note it is repeating fisrt with xml then with ClinicalDocument


xml
atrib.baseName id
atrib.baseName code
atrib.baseName title
atrib.baseName versionNumber
atrib.baseName template
atrib.baseName setId
atrib.baseName author
atrib.baseName recordTarget
atrib.baseName customerADT [red]<there are children under here I need to get for example [/red]
atrib.baseName test
atrib.baseName recordSource
atrib.baseName relatedDocument
atrib.baseName component
atrib.baseName log
ClinicalDocument
atrib.baseName id
atrib.baseName code
atrib.baseName title
atrib.baseName versionNumber
atrib.baseName template
atrib.baseName setId
atrib.baseName author
atrib.baseName recordTarget
atrib.baseName customerADT
atrib.baseName test
atrib.baseName recordSource
atrib.baseName relatedDocument
atrib.baseName component
atrib.baseName log

Thanks for helping me through this!

DougP, MCP, A+
 
the name is Fred Flinstone and SSN is bogus

Ok now I have this code which gets all the nodes BUT!!!
there are Keys and values under some of the nodes that I need to get at.
Code:
    Dim objDoc As MSXML2.DOMDocument40
    Dim objNode As MSXML2.IXMLDOMNode
    
    Set objDoc = New MSXML2.DOMDocument40
    
    ' Load XML from a user-defined file path.
    objDoc.Load "C:\VBSafeSource\CURRENT ACTIVITY\Document9.xml"
    
    ' Recursively list each node's name and data value.
    Call GetChildNodes(objDoc.childNodes)
------------
Public Sub GetChildNodes(ByVal nodeList As MSXML2.IXMLDOMNodeList)
    Dim objNode As IXMLDOMNode
    For Each objNode In nodeList
        ' If there are child nodes, call this subroutine again.
        If objNode.hasChildNodes = True Then
            Call GetChildNodes(nodeList:=objNode.childNodes)
        Else
            debug.print objNode.parentNode.NodeName & ": " & objNode.nodeTypedValue
         End If
    Next objNode
End Sub
this prints like so
#document: version="1.0"
ClinicalDocument:
ClinicalDocument:
title: General Medicine Report
ClinicalDocument:
mm:titles:
mm:titles:
mm:titles:
mm:titles:
etc
etc
but in the XML there are these Keys and values and codes as such
<mm:titles>
<mm:title code="5005" name="Past Surgical History"/>
<mm:title code="5008" name="Family History"/>
<mm:title code="5012" name="Review of Systems"/>
<mm:title code="5010" name="Current Medications"/>

which is just shows mm:titles 10 times in a row and nothing after it

How do I get at these pieces of information?

DougP, MCP, A+
 
I don't code in VB, but maybe something like this:
Code:
Public Sub GetChildNodes(ByVal nodeList As MSXML2.IXMLDOMNodeList)
    Dim objNode As IXMLDOMNode
    For Each objNode In nodeList
        debug.print objNode.NodeName & ": " & objNode.nodeTypedValue
        For Each att In objNode.attributes
            debug.print att.name & ": " att.value
        Next att
        If objNode.hasChildNodes = True Then
            Call GetChildNodes(nodeList:=objNode.childNodes)
        End If
    Next objNode
End Sub

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Ok I'm very close now, just one final thing
Need to get the "Name" of a tag
such as
here is my code now

Code:
Public Sub ListAllNodes(XMLFileName)
    
    Dim objDoc As MSXML2.DOMDocument40
    Dim objNode As MSXML2.IXMLDOMNode
    
    Set objDoc = New MSXML2.DOMDocument40
    
    ' Load XML from a user-defined file path.
    objDoc.Load XMLFileName
    
    ' Recursively list each node's name and data value.
    Call GetChildNodes(objDoc.childNodes)
    
End Sub
------------------------
Public Sub GetChildNodes(ByVal nodeList As MSXML2.IXMLDOMNodeList)
   On Error GoTo Err_GetChildNodes
    Dim attrib As IXMLDOMAttribute
    Dim parentItem As Object
    Dim objNode As Object
    For Each objNode In nodeList
        ' If there are child nodes, call this subroutine again.
        If objNode.hasChildNodes = True Then
            Call GetChildNodes(nodeList:=objNode.childNodes)
        Else
            Dim parentNode As String
            parentNode = objNode.parentNode.NodeName
            'parentItem = objNode.
            Debug.Print objNode.parentNode.NodeName & ": " & objNode.nodeTypedValue
            If objNode.parentNode.hasChildNodes Then
            
            Debug.Print objNode.nodeType
            If Not objNode.Attributes Is Nothing Then     'get error here if no attributes in it (object not set)
               For Each attrib In objNode.Attributes
                  
                'get the MT-world customer properties

                Debug.Print parentNode; tvwChild; "baseName =" & attrib.baseName & "|" & "Value =" & attrib.Value
                Debug.Print attrib.NodeName
                Debug.Print attrib.Value
                
               [red]If parentNode = "mm:propertyGroup" And attrib.Value = "MT-World Group" Then[/red]
                     SaveData = True
               End If
               'And atrib.baseName = "MT-World" Then
                  If SaveData Then
                     If atrib.baseName = "key" Then
                        FieldName = atrib.Value
                     ElseIf atrib.baseName = "value" Then
                        FieldValue = atrib.Value
                        If FieldName <> "" Then
                        Rs1.fields.item(FieldName).Value = FieldValue
                        End If
                        List1.AddItem FieldName & " : " & FieldValue
                     End If
                End If

               Next
            End If
         End If
         End If
    Next objNode
Problem is in [red]RED[/red] the parentNode = mm:propertyGroup
but the attrib.Value Never = "MT-World Group" this is another property of some sort
here is the XML to go with it
Code:
<mm:propertyGroup [red]name="MT-World Group"[/red]>  
<mm:property key="PatientPrefix" value="" type="0"/>
<mm:property key="PatientGiven" value="Fred" type="0"/>
<mm:property key="PatientFamily" value="Flintstone" type="0"/>
As its coming through the loop it gets mm:propertyGroup in parentnode but atrib.baseName = blank
the child nodes below work perfect as shown below
parentnode = PatientPrefix & value =""
parentnode = PatientGiven & value="Fred"
parentnode = PatientFamily & value="Flintstone"

TIA


DougP, MCP, A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top