Re: XPath and default (overridden) namespaces

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Oleg Tkachenko [MVP] (oleg_at_NO!SPAM!PLEASEtkachenko.com)
Date: 08/26/04


Date: Thu, 26 Aug 2004 13:33:29 +0200

Peter Theill wrote:

> I need some help on XPath ... what's the expressions to get:
>
> 1. All "Employee" nodes?

You should realize that namespace is integral part of an element name,
so "All "Employee" nodes" actually makes little sense. You mean all
elements with local name "Employee"? Then use
/NorthwindEmployees/*[local-name='Employee']

> 2. Only "Employee" nodes from "urn:test1" namespace?

/NorthwindEmployees/foo:Employee
where foo prefix is bound to "urn:test1" namespace.

Or (usually machine-generated form)

/NorthwindEmployees/*[local-name='Employee' and namespace-uri()='urn:test1']

PS. Make sure you read "XML Namespaces and How They Affect XPath and
XSLT" at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml05202002.asp

-- 
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


Relevant Pages

  • Re: Hungarian notation pros vs cons
    ... be in a different namespace than Employee. ... typing, but only when you declare the object or are tryign to cast it. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Hungarian notation pros vs cons
    ... But what about in the database where you can't organize by namespace? ... Even if namespaces didn't solve this, Employee would be a bad ... >> Does anyone disagree with using Hungarian notation? ... > 4) It's inconsistent with the rest of the framework. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: CrystalReport1.prt
    ... So just like any other object, you need the namespace to get to it. ... Employee e = new Employee; ... If you named your report "EmployeeByDepartmentReport", ... I see some sample code using statements like "private CrystalReport1 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Why use relational tables in OO (please just take a look inside)
    ... a table is defined with just one field -- employee pointer ... Because employee pointers are included directly in the indexes, ... using namespace boost; ... typedef tableemp_table; ...
    (comp.object)
  • lxml namespaces problem
    ... I have a little problem with XML namespaces. ... The first one looks for nodes in 'ns1' ... namespace, and substitutes them, according to some algorithm. ... it confuses some other processors ...
    (comp.lang.python)