Solved

Need help getting  node data

Posted on 2001-07-24
5
179 Views
Last Modified: 2012-06-21
hi-

i have the following xml data loaded into a dom document.

<?xml version="1.0" ?>
 <PEOPLE>
  <PERSON>
    <SN>
      <![CDATA[Smith]]>
    </SN>
    <GIVEN_NAME>
      <![CDATA[Jeremy]]>
    </GIVEN_NAME>
   <EMAIL>
    <![CDATA[Jeremy.Smith@usa.com]]>
   </EMAIL>
  <PHONE>
    <![CDATA[ ]]>
  </PHONE>
 </PERSON>
</PEOPLE>

aslo, i have a snippet of code below i am working with. i need to pull the email field out of the document and place it in a string. can someone please show me how to do this? thanks- js


Dim mobjXMLDocument As MSXML2.DOMDocument30

Set mobjXMLDocument = New MSXML2.DOMDocument30

msLinkXML = mobjDXeroxLinkAdmin.GetLink(vnLinkID)
mobjXMLDocument.loadXML (msLinkXML)
0
Comment
Question by:jeremiahscott
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
Dave_Greene earned 100 total points
ID: 6314250
Option Explicit

Dim oDOM      As DOMDocument
Dim oRoot     As IXMLDOMNode
Dim oNode     As IXMLDOMNode
Dim oNodeList As IXMLDOMNodeList

Private Sub Command1_Click()

 Set oDOM = New DOMDocument
 Dim i As Long
 
 oDOM.Load "C:\One.xml"

 Set oRoot = oDOM.selectSingleNode("PEOPLE")
 
 Set oNodeList = oRoot.selectNodes("PERSON")
 
 MsgBox oNodeList.Length
 
 For i = 0 To oNodeList.Length - 1
   Set oNode = oNodeList.Item(i)
   Set oUpdateNode = oNode
   strEmail = oUpdateNode.Attributes.getNamedItem("EMAIL").Text = strNewVALUE
   MsgBox strEmail
End Sub

Private Sub Form_Unload(Cancel As Integer)
 Set oDOM = Nothing
 Set oNode = Nothing
 Set oNodeList = Nothing
End Sub
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6314256
Sorry,

Correct this line like so
strEmail = oUpdateNode.Attributes.getNamedItem("EMAIL").Text

Just comment with questions
0
 
LVL 27

Expert Comment

by:BigRat
ID: 6314264
Using the method selectSingleNode by passing the "path" to the node. This would be roughly :-

     Dim rootNode = mobjXMLDocument.documentElement;

     string = rootNode.selectSingleNode('/PEOPLE/PERSON/EMAIL');

BUT

    you'll be wanting to select a particular person's e-mail and not the first one. To do this you'll have to navigate throughout the document, and to do that you'll need to understand two things. First what procedures call be called and how to address the elements with "path" expressions. I'd arm myself with the DOM and XPath documentation from a W3C site.

Anyway to select a person we would write :-

     Dim personNode = root.selectSingleNode('/PEOPLE/PERSON[SN="' + Person + ']"');

which points the personNode at the node <PERSON> where the SN node underneath equals Person. Then you'd select the e-mail node as :-
 
    Dim emailNode = personNode.selectSingleNode('EMAIL')

(And carefully note no SLASH / infornt of EMAIL since this is a RELATIVE path name from the current node)

And I hope that gets you started!

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6314330
Just as SirRat mentioned...

If you have a unique key to each node you can search...

Set m_ActiveNode = m_XML_DOM.selectSingleNode("Markup/HyperLinks/Link[@Line $eq$ " & nLineNo & "][@Offset $eq$ " & nOffset & "]")
0
 

Author Comment

by:jeremiahscott
ID: 6314402
yup, this did the trick. thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSD Data to SQL Tables 2 25
json format text only 4 75
Change to event 1 100
Optimum versions of Selenium Webdriver with Python On Windows 7 1 80
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now