Solved

Need help getting  node data

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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

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