Microsoft Knowledge Base Email Alertz

KBAlertz.com: Specifying an XPath query as the query string parameter in a call to the

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 280457 - Last Review: October 12, 2001 - Revision: 1.2

PRB: Specifying Fully Qualified Element Names in XPath Queries

This article was previously published under Q280457

On This Page

SYMPTOMS

Specifying an XPath query as the query string parameter in a call to the selectNodes or selectSingleNode MSXML DOM methods may generate the following error message when the query includes one or more fully qualified element names in the NamespacePrefix:ElementName format:
Run-time error '-2147467259(80004005)': Reference to undeclared namespace prefix : '<Namespace Prefix>'

CAUSE

The SelectionNamespaces property of the MSXML DOMDocument object has not been set to specify the namespaces that are used in the XML document.

RESOLUTION

Use the SetProperty method of the MSXML DOMDocument object to set its SelectionNamespaces property and specify the namespaces to be used in the XML document.

STATUS

This behavior is by design.

MORE INFORMATION

If a newer version of MSXML has been installed in side-by-side mode, you must explicitly use the Globally Unique Identifiers (GUIDs) or ProgIDs for that version to run the sample code. For example, MSXML version 4.0 can only be installed in side-by-side mode. For additional information about the code changes that are required to run the sample code with the MSXML 4.0 parser, click the following article number to view the article in the Microsoft Knowledge Base:
305019  (http://kbalertz.com/Feedback.aspx?kbNumber=305019/EN-US/ ) INFO: MSXML 4.0 Specific GUIDs and ProgIds

Steps to Reproduce Behavior

Namespace support when querying the DOM by using XPath was first introduced in version 3.0 of the MSXML parser. Version 3.0 is currently the latest release of the MSXML parser. You need to install MSXML version 3.0 on your development computer to set up and test the following code sample.

The latest version of the MSXML parser and the MSXML 3.0 SDK can be downloaded from MSDN online XML Developer Center on the following Web site at:
http://msdn.microsoft.com/xml (http://msdn.microsoft.com/xml)
Execute the following steps in sequence to reproduce the problem described in the "Symptoms" section of this article:
  1. Save the following XML code on your hard drive in a file called Books.xml:
    <?xml version="1.0"?>
    <bk:Books xmlns:bk='http://myserver/myschemas/Books'>
      <bk:Book>
          <bk:Title>Just XML</bk:Title>
      </bk:Book>
      <bk:Book>
          <bk:Title>Professional XML</bk:Title>
      </bk:Book>
      <bk:Book>
          <bk:Title>XML Step by Step</bk:Title>
      </bk:Book>
      <bk:Book>
          <bk:Title>XML By Example</bk:Title>
      </bk:Book>
    </bk:Books>
    					
  2. Open a standard EXE project in Visual Basic. Form1 is created by default.
  3. On the Project menu, click References, and then set a reference to Microsoft XML, v3.0.
  4. Drag-and-drop a Command button onto Form1.
  5. Copy and paste the following code into the Click event procedure of the Command button, and specify the path to Books.xml in the doc.Load statement:
    Dim doc As MSXML2.DOMDocument30
    Dim BookList As MSXML2.IXMLDOMNodeList
    Dim BookElem As MSXML2.IXMLDOMElement
    
    Set doc = New MSXML2.DOMDocument30
    
    doc.Load "<path to Books.xml>"
    doc.setProperty "SelectionLanguage", "XPath"
    'doc.setProperty "SelectionNamespaces", "xmlns:bk='http://myserver/myschemas/Books'"
    
    Set BookList = doc.selectNodes("//bk:Book[position()<=2]")
    For Each BookElem In BookList
      Debug.Print BookElem.Text
    Next
    
    Set doc = Nothing
    					
  6. Save and run the project, and note that clicking the Command button when Form1 is displayed generates the following error message:
    Run-time error '-2147467259(80004005)': Reference to undeclared namespace prefix : 'bk'
  7. Stop the execution of the project, and uncomment the following line of code in the Command button's Click event procedure:
    doc.setProperty "SelectionNamespaces", "xmlns:bk='http://myserver/myschemas/Books'"
    					
  8. Save and run the project again, and note that clicking the Command button now displays the Titles of the first two Book elements in Books.xml. The XPath query specified as the QueryString parameter in the call to the selectNodes() method of the DOMDocument30 object uses the position() XPath function to extract the first two Book elements.

APPLIES TO
  • Microsoft XML Parser 3.0
  • Microsoft XML Parser 3.0 Service Pack 1
  • Microsoft XML Core Services 4.0
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
Keywords: 
kbprb KB280457
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please