472,780 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

XSD Problem when using Xpath code

When I import an xml document in Visual studio and Genereate as schema
from it, and create a dataset from it, it adds this line into to the
root element of my xml file -
"xmlns="http://tempuri.org/nameOfRoot.xsd"

I have no idea what its pointing to & what is tempuri.org?

So when this tag is in my xml tag my xpath query never works.
But when I delete it work fine.

Can someone please tell me what that tag is any why its affecting my
Xpath queries?

Thanks
Nov 12 '05 #1
2 2802
"ree32" <re***@hotmail.com> wrote in message news:76*************************@posting.google.co m...
"xmlns="http://tempuri.org/nameOfRoot.xsd"

I have no idea what its pointing to & what is tempuri.org?
It's not pointing to anything. Namespaces in XML are supposed
to be URI's (Universal Resource Identifiers), and URI's can be
either URN's (Universal Resource Names) or URL's (Universal
Resource Locators). You're seeing a namespace URI that is
a URL, that's why it resembles something you'd type into the
Address bar of your favorite web browser.

Despite the fact that it may look like a URL, it is not intended
to be dereferenced. It may be, and frequently is, a totally
fictitious location.

tempuri.org (temp ... uri, and not stir-fried Japanese noodles)
is just a fictitious domain name that's used when Microsoft's
tools are autogenerating a namespace URI for you (often
because the developer didn't specify one on their own).
So when this tag is in my xml tag my xpath query never works.
But when I delete it work fine.
Your XPath expressions are probably not written to use name-
space prefixes, which means the XPath expression is querying
for nodes in the empty namespace. However, when this xmlns
declaration is in your XML the nodes are in the tempuri.org
namespace URI, not in the empty namespace. That's why it
looks to XPath as if you have nothing there to query against
and it never finds anything.
Can someone please tell me what that tag is any why its
affecting my Xpath queries?


I think I've covered these, on to the unmentioned question of
what to do about it. Without the xmlns namespace declaration
in the XML, you'll encounter problems later trying to read an
XML instance document into a DataSet. Therefore, I'd advise
writing a namespace-aware XPath Expression.

Let's assume right now that you're querying for the someCol
child elements of someRow, as in this example,

XmlNodeList nodes = doc.SelectNodes( "//someRow/someCol");

In order to write a namespace-aware XPath Expression using
prefixes you must first add ( prefix, namespaceURI) pairs to
an XmlNamespaceManager. Next, you write the XPath
Expression to use the prefix to qualify each local element
name. Finally, in the call to SelectNodes( ) you must pass
the XmlNamespaceManager that knows about these prefixes
so the XPath processor can resolve them to namespace URIs.
Here is what the updated code looks like,

XmlNamespaceManager nsMan = new XmlNamespaceManager( doc.NameTable);
nsMan.AddNamespace( "tns", "http://tempuri.org/nameOfRoot.xsd");
XmlNodeList nodes = doc.SelectNodes( "//tns:someRow/tns:someCol");

If you use code similar to this for your XPath expressions then
you should be able to find nodes within the DataSet's XML w/o
removing it's xmlns namespace declaration.
Derek Harmon
Nov 12 '05 #2
"Derek Harmon" <lo*******@msn.com> wrote in message news:ut*************@tk2msftngp13.phx.gbl...
XmlNamespaceManager nsMan = new XmlNamespaceManager( doc.NameTable);
nsMan.AddNamespace( "tns", "http://tempuri.org/nameOfRoot.xsd");
XmlNodeList nodes = doc.SelectNodes( "//tns:someRow/tns:someCol");


Wish I had a string on that article (noticed my omission just as I
clicked Send). As I mentioned, don't forget to pass nsMan to
the SelectNodes( ) method! :-)

XmlNamespaceManager nsMan = new XmlNamespaceManager( doc.NameTable);
nsMan.AddNamespace( "tns", "http://tempuri.org/nameOfRoot.xsd");
XmlNodeList nodes = doc.SelectNodes( "//tns:someRow/tns:someCol", nsMan);
Derek Harmon
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings...
2
by: gimme_this_gimme_that | last post by:
What xpath expression would return the category-item having uid sps002 ? <category-list> <category> <uid>GRIDS_MAIN_CATEGORY_UID</uid> <uid-type>Categories</uid-type> <category-item-list>...
0
by: Jay Allard | last post by:
Hello I posted this in the vb.net group on the 2/25/2004, but didn't get any response. Here's attempt 2. Does anyone know of a more appropriate place to post this? One new piece of...
4
by: Tomas Rivas | last post by:
I am trying to validate an xml file and schema and when I am trying to validate I am getting the following error. I have been trying to come out with a solution but I have failed so far. The...
8
by: Alpha | last post by:
I created the following code in my C# program but it's giving me error message at run time of : XML.XPATH.XPATHEXCEPTION : Namespace Manager or XSLTContext needed. This query has a prefix,...
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
3
by: Brian | last post by:
Using external XML, I'm trying to build a quiz, but I can't seem to specify the DataSource for the RadioButtonList within a Repeater ItemTemplate. I've tried a number of approaches, but I haven't...
1
by: luthriaajay | last post by:
How can I use XPATH to extract the value of Element Code in Java? I havent used this before so help appreciated. <Underlying> <Code>KGF</Code> </Underlying> Java Code:
5
by: rcronk | last post by:
I'm new to C#/.NET. I am writing some C#/.NET (2.0) classes that will allow someone to get and set values in an XML file using an XPath to point to the location of that data. It's more complicated...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.