473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="htt p://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 2881
"ree32" <re***@hotmail. com> wrote in message news:76******** *************** **@posting.goog le.com...
"xmlns="htt p://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 XmlNamespaceMan ager. 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 XmlNamespaceMan ager that knows about these prefixes
so the XPath processor can resolve them to namespace URIs.
Here is what the updated code looks like,

XmlNamespaceMan ager nsMan = new XmlNamespaceMan ager( doc.NameTable);
nsMan.AddNamesp ace( "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******** *****@tk2msftng p13.phx.gbl...
XmlNamespaceMan ager nsMan = new XmlNamespaceMan ager( doc.NameTable);
nsMan.AddNamesp ace( "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! :-)

XmlNamespaceMan ager nsMan = new XmlNamespaceMan ager( doc.NameTable);
nsMan.AddNamesp ace( "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
1823
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 are stored in a free-format XML document (in memory for the life of the session) and persisted to a database (as free text) on exit. I have taught my developers the basics of XPath, however I don't want to have to review XMLDOM code all over the...
2
1637
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> <category-item>
0
380
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 information: It fails on any method that it happens to hit first. I juggled the methods a bit, and it just doesn't matter. As soon as the XslTransform hits an extension function, it fails with an invalid argument exception.
4
1907
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 document validates ok in xmlSpy but it fails in VS2003. Is there any article or fix for this? Thnaks in advance. Error: ======
8
3770
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, variable or user defined function. Can someone see what I'm doing wrong? Thanks, Alpha private XPathDocument unityMessages = new XPathDocument("UnityMessages.xml");
3
6806
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> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
3
9170
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 really had any success. I'm pretty sure I should be casting my XPathSelect() call to something so I can get at its attributes. This seems like it should be easy, and maybe I'm missing something obvious. Does anyone have any ideas? Here is the...
1
1753
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
6033
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 than this but for simplicity's sake, I've trimmed it down to this. The problem I'm running into is I want to find the best way to add the data into the XML file if the XPath returns nothing. For example, some XPaths might already exist in the XML...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.