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

x
?
Solved

Need help getting  node data

Posted on 2001-07-24
5
Medium Priority
?
187 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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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. 
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

618 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