#### Xpath Search with Namespaces

I've run into a problem trying to search an XML document with a
namespace. Sample extract is below:

<Vendors xmlns="http://tempuri.org/Vendor.xsd">
<Vendor>
<VendorID>002010</VendorID>
<PropricerId>002010S</PropricerId>
<VendorName>AEROTEK, INC.</VendorName>
</Vendor>
<Vendor>
<VendorID>002012</VendorID>
<PropricerId>002012S</PropricerId>
<VendorName>ARONSON &amp; COMPANY</VendorName>
</Vendor>
<Vendor>
<VendorID>002018</VendorID>
<PropricerId>002018S</PropricerId>
<VendorName>ASSOCIATED SPRING RAYMOND</VendorName>
</Vendor>

I'm trying to get a VendorName based on a vendor ID.  I'm using
Microsoft .Net framework XML parser.

I've tried numerous variations on the following:

..SelectSingleNode("//default:Vendor/default:VendorName[VendorID='008300'],
<<Variable indicating namespace>>)

TIA,

Michael Schnell


 0
6/1/2005 5:59:54 PM
dotnet.xml 7266 articles. 0 followers.

2 Replies
756 Views

Similar Articles

[PageSpeed] 5

try the following:

..SelectSingleNode("a:Vendors/a:Vendor/a:VendorName[../a:VendorID='008300']")
where "a" maps to your namespace.

When you are using the predicate on VendorName, the context at that point is
inside the element VendorName, so you need to use the parent axis to access
VendorID like "../a:VendorID"

hope this helps,
swapna

"NOSPAM.schnell@rdacorp.NOSPAM.com" <schnell@rdacorp.com> wrote in message
> I've run into a problem trying to search an XML document with a
> namespace. Sample extract is below:
>
> <Vendors xmlns="http://tempuri.org/Vendor.xsd">
> <Vendor>
> <VendorID>002010</VendorID>
> <PropricerId>002010S</PropricerId>
> <VendorName>AEROTEK, INC.</VendorName>
> </Vendor>
> <Vendor>
> <VendorID>002012</VendorID>
> <PropricerId>002012S</PropricerId>
> <VendorName>ARONSON &amp; COMPANY</VendorName>
> </Vendor>
> <Vendor>
> <VendorID>002018</VendorID>
> <PropricerId>002018S</PropricerId>
> <VendorName>ASSOCIATED SPRING RAYMOND</VendorName>
> </Vendor>
>
>
> I'm trying to get a VendorName based on a vendor ID.  I'm using
> Microsoft .Net framework XML parser.
>
> I've tried numerous variations on the following:
>
> .SelectSingleNode("//default:Vendor/default:VendorName[VendorID='008300'],
> <<Variable indicating namespace>>)
>
> TIA,
>
> Michael Schnell
>


 0
6/2/2005 12:22:33 AM
Hi Michael,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the VendorName by
VendorID in an XmlDocument. If there is any misunderstanding, please feel
free to let me know.

According to the document you have provided, we cannot get the VendorName
directly using SelectSingleNode. Because the VendorID and VendorName is in
the same level of the document. However, we can get the parent Vendor node
with SelectSingleNode. Here is the code.

XmlDocument doc = new XmlDocument();
XmlNamespaceManager nsm = new XmlNamespaceManager(doc.NameTable);

XmlNode n =
doc.SelectSingleNode("//default:Vendor[default:VendorID='008300']", nsm);

Node n is the <Vendor> node. You can get the child <VendorName> element to
get the name.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


 0
v-kevy (347)
6/2/2005 5:32:31 AM

Similar Artilces:

XPath
Using XPath I am querying parts of XML document, " get quoted by \ - is it possible to specify not to quote " with \? <RootElement> <Element Attribute="SomeValue" /> </RootElement> XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); XmlNode xmlNode = xmlDoc.SelectSingleNode("//RootElement/Element") Print xmlNode.OuterXml <Element Attribute=\"SomeValue\"/> where I was expecting to get <Element Attribute="SomeValue"/> TIA Dennis wrote: > Using XPath I am querying parts of XML document,...

Get rid of Windows Search?
Recently, perhaps in the wake of some update from Microsoft, I am now vexed by WIndows Search. Seems that every time I click on a folder to open I get .. . . Windows Search. It could be something useful--if I wanted to search. But if this search engine--if that's what it is--is too dumb to realize that the difference between navigating and searching is not something I want to waste time trying to decipher. How can I get rid of this? Or at least put it back in a cage to use when I decide to use it? Click Start, Run and type this command: regsvr32 /i shell32.dll ...

How to configure SQL server 2005 to store/search multiple language
Hello, What specific areas do I have to take care of in order to meet the following requirements: 1. The database needs to store correctly content in English, Spanish, French, Japanese, and Korean. 2. The database needs to return correct results in full-text and field-based search for searches in the above languages. Thanks very much in advance for any info! -David On Mar 10, 2:21=A0pm, MDDC <M...@discussions.microsoft.com> wrote: > Hello, > > What specific areas do I have to take care of in order to meet the follow= ing > requirements: > &...

Getting a specific parent of any node via xpath navigation

Specialized search engine for Excel
I created a search engine for Excel using the new Google Co-Op. http://www.spreadsheetconverter.com/excel-search.htm It only searches the best sites dedicated to Excel, currently about 60. Do you think a site is missing? -- Mattias Good work. You have crated a useful tool. But how can we tell which sites are being searched?? -- Gary's Student "mattiasw" wrote: > I created a search engine for Excel using the new Google Co-Op. > > http://www.spreadsheetconverter.com/excel-search.htm > > It only searches the best sites dedicated to Excel, currently about ...

search for publisher file
is it possible to find a publisher file when doing a windows search. Yes. I assume you're having difficulties tho. -- JoAnn Paules Microsoft MVP - Publisher How to ask a question http://support.microsoft.com/kb/555375 "Pauline" <Pauline@discussions.microsoft.com> wrote in message news:F75DB370-0A6A-4791-A6EC-F61B7C24992D@microsoft.com... > is it possible to find a publisher file when doing a windows search. Pauline wrote: > is it possible to find a publisher file when doing a windows search. If you search for *.pub you will find all Publisher files. If y...

XPath pb
Hi In infopath, I use a XPath expression to get some nodes : var oEMailNodeList = XDocument.DOM.selectNodes("//Message/EMail"); My problem is that this method returns 0 items. Here is the DOM.xml property : <?xml version="1.0" ?> <?mso-infoPathSolution productVersion=\"11.0.5329\" PIVersion=\"1.0.0.0\" href=\"file:///C:\Documents%20and%20Settings\t-stevbe\Local%20Settings\Appli cation%20Data\Microsoft\InfoPath\7ab6e8af39fc42e2\manifest.xsf\" solutionVersion=\"1.0.0.9\" initialView=\"messagesList\" ?> <?...

Searching tables for similar entries
Hi, I have this customer table and a transaction table on another file. Is it possible to search the transaction table and calculate values on the transaction table and put it in the customer table? e.g Customer table -------------------- customer name accountno abc ltd 1238 bcd corp 3456 Trans table -------------------- accountno price qty 1234 00* 10 5 3456 00* 20 1 1234 00* 2 3 *The file i received have this formating 1234<afewspace>00 and I was unable to use vlookup to match the tables. Thanks in advance....

How to pass a Nodeset to an XPath extension function?
I am using the .NET framework v2.0.40607 with Visual C# Express and I would like to create some custom XPath functions to use directly in a XSLT stylesheet. I called System.Xml.Query.XmlArgumentList.AddExtensionObject(string, object) to register the functions I've written. The functions that take a String, Boolean or Number parameter work perfectly. However, I do not know how to create a function that will accept a Nodeset as a parameter. I tried writting a function taking a XPathNavigator object, but it does not work for all XPath queries that return a Nodeset: I get an error &qu...

XPath Validation
I'm looking for a way to Validate an XPath prior to executing the expression, without using a try catch clause. For example: I'm looking for something that would tell me that "\some/Xpath\to\Node" is invalid... Any Ideas? Hi, As far as I know, the .NET framework could not validate XPath directly with class library. The only thing we can do is to use try/catch block. Or you can try to find some 3rd-party tool such as XML spy to validate it. HTH. Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights." Thanks K...

Global Search
Anyway to do a "global Search" for a word that could be used as a field name or in a query or in the code (Not DATA)? I have changed a misspelled field name in a table and I want to find every instance of the old spelling so I can be sure they are all changed. Thanks Download a copy of Rick Fisher's "Find and Replace" utility. http://www.rickworld.com/download.html -- --Roger Carlson MS Access MVP Access Database Samples: www.rogersaccesslibrary.com Want answers to your Access questions in your Email? Free subscription: http://peach.ease.lsoft.com/scrip...

Tricky XPath query
Hi all, I've just changed the structure of my XML file and now I need to construct an XPathNavigator object that uses tags from two different levels in the XML file. For example: <someTag> <innerTagA> <innerInnerTagA> <innerInnerInnerTagA> Some Data That Belongs Here </innerInnerInnerTagA> <innerInnerInnerTagB> Some Data that Belongs More Specifically Here </innerInnerInnerTagB> </innerInnerTagA> <innerInnerTagB> <innerInnerInnerTagZ> This Data should real...

Search between two dates
Hi everyone I've got information in a SQL Server Database. I'm viewing the data using MS Excel, e.g Data, Get External Data, Create New Query (on the toolbar). Now using the wizard I have got to Microsoft Query. What I want the system to do is..... When I open the spreadsheet a pop up box appears where the user types in the FROM date, then a second pop up box appears where the user types in the TO date. The values that are shown on the spreadsheet are the values between the two dates (including the FROM and TO dates). Is this quite easy? Thanks for any help David -- David4...

Xpath with namespaces
Hello Everyone, I am having an issue with xml and namespaces, at least I think it is namespaces. When I use namespaces, I cannot use SelectSingleNode / SelectNodes as they always return 0/Nothing respectively. Anyone have any thoughts? Thanks in advance VB.Net 2005 WinXP Sp2 Test code: Dim objXML As System.Xml.XmlDocument 'Test XML 1 ==> Always returns 0 objXML = New System.Xml.XmlDocument objXML.Load(Application.StartupPath & "\xmlfile1.xml") MsgBox(objXML.SelectNodes("top/middle").Count) 'Test XML 2 ==> Always re...

Search cells with many numbers a few numbers?
In Excel, I'd like to search cells which have many numbers in each, they are separated by spaces. I'd like to look in the cells for a few numbers. The logic statements do not seem to work. How do I do this? ...

How to Change Defualt Search Engine?
Does anyone know how to change the default search engine that appears when clicking on the "Search the Web" button on the Web toolbar from within Outlook 2002? Currenlty when I click that button, I get MSN search engine. I would like to change to Google. Thanks! I believe you would have to set the following registry keys. [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main] "Search Page"="http://www.google.com" "Search Bar"="http://www.google.com/ie" [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchURL] "...

xpath??
Hi, I am very new to xml. I have a datatable I need to group by and was suggested that xml and xpath might be the way to go. I converted the datatable to xml but don't know what to do next. Can anyone point me to the right direction. This is what I am trying to do: - have datatable (~300k rows and 5 cols) - need to group by column1(string catagory) and column2(date) - display the totals by column1 and column2 in datagrid. Any help is appreciated. Thanks. The advice to convert the database to XML was clearly a bad joke. RDBMSes are best at what they can do best -- work with relational da...

A Form for searching information
Sorry this may be a very stupid questions to all of you... I have a form based on a single table (say, tblStudent) with a key field, say, StudentID. I want to design a form which on entering an ID into the StudentID control, the remaining information from the tblStudent will be populated into a form automatically. How can I do this? Do I need to use macros? Thanks for your advice. "Fred" <Fred@discussions.microsoft.com> wrote in message news:8695B0A7-00DC-4B48-BE87-13C2CF40BA74@microsoft.com... > Sorry this may be a very stupid questions to all of you... > >...

Search Folder Limit?
I have created a search folder in Outlook 2003 that includes criteria to select all messages from specific people. I included 6 people and 1 distribution list, but it doesn't seem to pick up all of the different folks I added. These contacts were added from the Global Address list, not the personal contacts list. Is there a limit to the number of people or objects that you can have in a search folder criteria? I did confirm that the missing e-mails are in the inbox just like the others that ARE showing up. Thanks for any assistance! Geoff ...

IE8
I'm not aware of what causes this problem. After IE8 displays the homepage, a message pops up stating a program has attempted to change the default search provider .. blah blah. Bing is now the default search provide and can not be changed. The "Set as default" button does nothing. Operating System: Windows XP Home Edition SP3 What anti-virus application or security suite is installed and is your subscription current? What anti-spyware applications (other than Defender)? What third-party firewall (if any)? Were any of these applications running in the backgr...

Search in outlook
Is there a way to search in outlook, so that it starts with the most recent, instead of starting with the oldest one For Outlook 2003 and previous and on Windows XP; No, the native search does not support that; it starts with the first item that is stored in the pst-file (this does not have to be the oldest in terms of received) You can do this when you install an indexing tool such as Windows Desktop Search; http://www.microsoft.com/windows/products/winfamily/desktopsearch/default.mspx When using Outlook 2007 or Outlook 2010 on Windows Vista or Windows 7, the data in Outlook...

Outlook Search #3
Still looking for an answer to my prior post: The search function in my Outlook 2007 has stopped working. I use it frequently to find calendar entries and various emails. I don't know what happened to make it stop working. How can I restore the function? I tried doing a re-Index (as suggested by the help file) but it still isn't working. if i were you, i would take a third-party-searchtool for outlook... i use lookeen for my outlook and i´m very happy with it, perhaps you should try it www.lookeen.com "Jan Groshan" wrote: > Still looking for an answer to ...

Module for searching multiple .doc files on multiple terms?
Hello All, Info on system setup: So I have an Access 2003 DB that is being used for career opportunities. This database sits behind my website where people can go to submit applications and upload their resumes in word.doc format. Every time a resume is upload it is place on a network drive that has a folder named "Resumes". This folder contains about 8500 files. My question... Is there any sort of method that can be used to do a search on all of these word.doc's using multiple criteria? I know that you can do a simple search using Windows that would be "on...

fail to search text in old emails
my emails are located in my imap server. after reinstallation of XP, Office, Outlook Express and Microsoft Outlook from chinese and english version, i can no longer search the text in the messages before the installation. e.g. Message 1: hello! Message 2: test ^ before Apr 20 (reinstallation) v after message 3: foo message 4: claim a search of "hell" can no longer return message 1 to me but "lai" can return message 4. ...

DHCP Search timeout / Multi-homing
I have a laptop that I use at several locations. Most of the locations use a DHCP, but a few require fixed IPs. I have the NIC set for DHCP with the alternate settings set to the fixed IP info. This works fin except it takes the computer 60 seconds or so before the search for DHCP times out and it defaults to the fixed settings. Is there a way to reduce the DHCP search timeout so it will default to the fixed settings faster? If not, I have been looking into multi-homing the NIC. I tried setting HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSetServices\Tcpip\Parameters\Interfaces\(...