Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 5th, 2006, 12:42 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use XPath to retrieve a node tag rs:data?

I have a XML file:

Code:
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
    xmlns:rs='urn:schemas-microsoft-com:rowset'
    xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
    <s:ElementType name='row' content='eltOnly' rs:updatable='true'>
        <s:AttributeType name='PLATE_PK' rs:number='1' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='int' dt:maxLength='4' rs:precision='0' rs:fixedlength='true'/>
        </s:AttributeType>
        <s:AttributeType name='BARCODE_ID' rs:number='2' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' dt:maxLength='20' rs:precision='0'/>
        </s:AttributeType>
        <s:AttributeType name='INSPECT_NUMBER' rs:number='3' rs:nullable='true' rs:maydefer='true' rs:write='true'
             rs:writeunknown='true'>
            <s:datatype dt:type='i2' dt:maxLength='2' rs:precision='0' rs:fixedlength='true'/>
        </s:AttributeType>
        <s:AttributeType name='PLATE_STATUS' rs:number='4' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' dt:maxLength='20' rs:precision='0'/>
        </s:AttributeType>
        <s:AttributeType name='INSPECT_DATE' rs:number='5' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='dateTime' rs:dbtype='variantdate' dt:maxLength='16' rs:precision='0' rs:fixedlength='true'/>
        </s:AttributeType>
        <s:AttributeType name='DIR_PATH' rs:number='6' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' dt:maxLength='200' rs:precision='0'/>
        </s:AttributeType>
        <s:AttributeType name='PLATE_IMAGE' rs:number='7' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' dt:maxLength='25' rs:precision='0'/>
        </s:AttributeType>
        <s:AttributeType name='TYPE_ID' rs:number='8' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' dt:maxLength='2' rs:precision='0'/>
        </s:AttributeType>
        <s:AttributeType name='MAX_SCORE' rs:number='9' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='i2' dt:maxLength='2' rs:precision='0' rs:fixedlength='true'/>
        </s:AttributeType>
        <s:AttributeType name='USER_NAME' rs:number='10' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' dt:maxLength='60' rs:precision='0'/>
        </s:AttributeType>
        <s:AttributeType name='PROPERTIES' rs:number='11' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' dt:maxLength='255' rs:precision='0'/>
        </s:AttributeType>
        <s:AttributeType name='source_key' rs:number='12' rs:write='true'>
            <s:datatype dt:type='int' dt:maxLength='4' rs:precision='0' rs:fixedlength='true' rs:maybenull='false'/>
        </s:AttributeType>
        <s:extends type='rs:rowbase'/>
    </s:ElementType>
</s:Schema>
<rs:data>
    <z:row BARCODE_ID='IB-APY0SQ' INSPECT_NUMBER='4' PLATE_STATUS='Completed' INSPECT_DATE='2006-03-06T23:48:43'
         DIR_PATH='\\sgc-web\Pub\Images\IB-APY0SQ\' PLATE_IMAGE='Thmb_IB-APY0SQ' TYPE_ID='IB' MAX_SCORE='-1' USER_NAME='OPERATOR'
         source_key='0'/>
    <z:row BARCODE_ID='IB-APY0SQ' INSPECT_NUMBER='3' PLATE_STATUS='Completed' INSPECT_DATE='2006-03-01T01:30:09'
         DIR_PATH='\\sgc-web\Pub\Images\IB-APY0SQ\' PLATE_IMAGE='Thmb_IB-APY0SQ' TYPE_ID='IB' MAX_SCORE='-1' USER_NAME='OPERATOR'
         source_key='0'/>
    <z:row BARCODE_ID='IB-APY0SQ' INSPECT_NUMBER='2' PLATE_STATUS='Completed' INSPECT_DATE='2006-02-24T13:46:31'
         DIR_PATH='\\sgc-web\Pub\Images\IB-APY0SQ\' PLATE_IMAGE='Thmb_IB-APY0SQ' TYPE_ID='IB' MAX_SCORE='-1' USER_NAME='OPERATOR'
         source_key='0'/>
    <z:row BARCODE_ID='IB-APY0SQ' INSPECT_NUMBER='1' PLATE_STATUS='Completed' INSPECT_DATE='2006-02-20T10:49:44'
         DIR_PATH='\\sgc-web\Pub\Images\IB-APY0SQ\' PLATE_IMAGE='Thmb_IB-APY0SQ' TYPE_ID='IB' MAX_SCORE='-1' USER_NAME='OPERATOR'
         source_key='0'/>
</rs:data>
</xml>

When I use

Code:
XPathNodeIterator nodes = navigator.Select("//rs:data/z:row");
in C# to obtain the rows, in debugging mode the following error showed up:

Code:
Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.
How should I modify my program so these can be obtained using XPath?

This is my code:

Code:
        static void ReadXML(String filename)
        {
            XPathDocument document = new XPathDocument(filename);

            XPathNavigator navigator = document.CreateNavigator();
            XPathNodeIterator nodes = navigator.Select("//rs:data/z:row");

            while (nodes.MoveNext()) {
                Console.WriteLine(nodes.Current.Name);
            }
        }
Thanks!

Reply With Quote
  #2 (permalink)  
Old May 5th, 2006, 01:11 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's example code for doing this at:

http://discuss.develop.com/archives/...et&D=0&P=96885

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath to get next node (sibling) jeft0nes XSLT 2 August 8th, 2007 08:30 PM
How Retrieve data of a node or from an element chandu.mca007 XML 1 December 16th, 2006 03:11 PM
XPATH: Retrieve Value without namespace prefixes ramesh.kumarm XSLT 4 September 14th, 2006 03:50 AM
XPath node selection nkuar XML 1 March 4th, 2006 09:40 PM
Read xpath query from node value jaquing XSLT 2 January 11th, 2006 06:50 PM



All times are GMT -4. The time now is 11:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.