Solved

Need help getting  node data

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

13 Experts available now in Live!

Get 1:1 Help Now