Solved

Need help getting  node data

Posted on 2001-07-24
5
182 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
[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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i generate these XML with SimpleXML() 5 81
Word files to Wordpress Posts 2 73
xpath sql query 2008 8 63
XML SQL 8 30
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

696 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