Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2009, 03:38 AM   PM User | #1
musicgold
New Coder

 
Join Date: Oct 2008
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
musicgold is an unknown quantity at this point
XML - Xpath queries not working in some cases

Hi,

I am new in XML. But I have done coding in VBA, C, and HTML. I am using VBA to extract data from an xml file. I use Xpathbuilder to generate Xpath queries for my work. However, some Xpath queries are causing errors in my program. As I am new in xml and its standards I am not sure what is causing them. Answers to the following questions might help me in understanding these problems better. Can you please help me? Thanks.

1. Which version of xml am I using? In my program I declare variables as shown here. Dim oDoc As MSXML2.DOMDocument, Dim oNodeList As msxml2.IXMLDOMNodeList. Also, in Refrences of the VBA environment I have selected Microsoft xml.V6.0. I have Microsoft XP and Office 2003 SP2.

2. Why the SelectionLanguage property is not working? When I put the following statement in my code, the selectnodes statement gives me an error. Selectnodes work fine without this statement. I don’t know why this is happening.
oDoc.setProperty "SelectionLanguage", "XPath"

3. Why the Selectnodes statement is not working for a few queries? I am using this statement:
Set oChildren = oDoc.selectNodes(Path). This statement works for simple queries such as
Path = /FSK:Research/FSK:Product/FSK:Context/FSK:IssuerDetails/FSK:Issuer/FSK:SecurityDetails/FSK:Security
But causes an error for
Path =
/FSK:Research/FSK:Product/FSK:Context/FSK:IssuerDetails/FSK:Issuer/FSK:SecurityDetails/FSK:Security [@securityID='1404']
Or Path =
/FSK:Research/FSK:Product/FSK:Context/FSK:IssuerDetails/FSK:Issuer/FSK:SecurityDetails/FSK:Security/FSK:FinancialGroup [2]

Note that I have verified these paths using Xpathbuilder.

I am also attaching my code below.

Thanks.


Code:
        Dim oDoc As msxml2.DOMDocument
        Dim fSuccess As Boolean
        Dim oRoot As msxml2.IXMLDOMNode
        Dim oBegining As msxml2.IXMLDOMNode
        Dim oAttributes As msxml2.IXMLDOMNamedNodeMap
        Dim oCountryName As msxml2.IXMLDOMNode
        Dim oChildren As msxml2.IXMLDOMNodeList
        Dim oChild As msxml2.IXMLDOMNode
        Dim oNodeList As msxml2.IXMLDOMNodeList
        
        Dim Startcell As Range
        Dim temp As String
        Dim temp2 As String
        Dim Colno As Integer
        Dim oCell As Range
        Dim Path As String
        Dim Counter As Integer

On Error GoTo Exitfun
    
    Set oDoc = CreateObject("MSXML2.DOMDocument")
    
    oDoc.async = False
    oDoc.validateOnParse = False
    
    oDoc.Load ("c:\test.xml")

  ' MsgBox oDoc.XML
        
    Worksheets("Template").Select
    
    Set oRoot = oDoc.documentElement

    Set oNodeList = oDoc.getElementsByTagName("FSK:SecurityName")  This works fine.

     temp = oNodeList.Item(0).childNodes.Item(0).Text
     
         
    Set Startcell = ActiveCell
    Counter = 0     ' to count columns
    
    For Each oCell In Worksheets("Instructions - Introduction").Range("G1:G21")
    
        
    Path = oCell.Value
        
   Set oChildren = oDoc.selectNodes(Path) This doesn't work sometimes.
        
   Startcell.Offset(0, Counter).Value = oChildren.Length
    
    Counter = Counter + 1
    Next
Exit Sub

Exitfun: MsgBox "Error occured" & Counter

End Sub

Last edited by musicgold; 01-11-2009 at 03:48 AM..
musicgold is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:36 PM.


Advertisement
Log in to turn off these ads.