Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > XML General > .NET and XML

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-28-2008, 09:55 AM
Joe Fawcett
 
Posts: n/a

Default Re: Can someone help me to understand schema locations?



There's no prefix on the Report element so it's in the default namespace.
The default namespace is indicated via an xmlns 'attribute' (with no prefix)
on the element or one of its parents. So in this case it's:
xmlns="Data_Feed"
That's what you'd see if you examined xDoc.DocumentElement.NamespaceURI in
the debugger.

The other namespace declaration has a prefix attached, xmlns1, so that
only pertains to nodes with a p1 prefix such as the p1:schemaLocation
attribute.

As an aside using p1 as a prefix is perfectly legal but a little unusual,
most examples using the schema instance namespace,
http://www.w3.org/2001/XMLSchema-instance, use xsi as the prefix.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"SeanInSeattle" <SeanInSeattle@discussions.microsoft.com> wrote in message
news:4EFC6F13-EA9D-4EF6-A512-120745D1CE28@microsoft.com...
> Ah, yes. I appreciate that. Though, which one is the URI in my example
> xml?
> Is it the p1:schemalocation value altogether, or just the "http://[...]",
> or
> is it the xmlns1 value?
>
> Here's my code:
>
>
Code:
> try {
> XmlDocument xDoc = new XmlDocument();
> xDoc.Load(XMLDoc_URL);
> System.Xml.XmlNamespaceManager xmlnsManager = new
> System.Xml.XmlNamespaceManager(xDoc.NameTable);
> xmlnsManager.AddNamespace(strDataFeedName,
> xDoc.DocumentElement.NamespaceURI);
> foreach (System.Xml.XmlNode xnDetail in
> xDoc.DocumentElement.SelectNodes(XPathToData, xmlnsManager))
> Console.WriteLine(xnDetail.Attributes.GetNamedItem(AttrName).Value);
> }catch (Exception e) { Console.WriteLine(e.Message); return -1; }
>
>
> "Martin Honnen" wrote:
>
>> SeanInSeattle wrote:
>> > I have this xml:
>> > [xml]
>> >
>> > <Report p1:schemaLocation="Data_Feed
>> > http://server/reportserver?param1=foo&param2=bar"
>> > Name="Data Feed"
>> > xmlns1="http://www.w3.org/2001/XMLSchema-instance"
>> > xmlns="Data_Feed">
>> > <Data/>
>> > </Report>
>> >
>> > [/xml]
>> >
>> > And, I'm trying to read it... without success. I'm using code from
>> > this
>> > KB318545 (http://support.microsoft.com/kb/318545), but not having much
>> > luck.
>> > That its not working is probably because I don't understand how to map
>> > the
>> > info above to the parameters needed for the xmlDoc.SelectNodes(xpath)
>> > to
>> > work.

>>
>> You need an XmlNamespaceManager
>> XmlDocument doc = new XmlDocument();
>> doc.Load("file.xml");
>>
>> XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
>> mgr.AddNamespace("df", doc.DocumentElement.NamespaceURI);
>>
>> foreach (XmlElement data in doc.SelectNodes("df:Report/dfata", mgr))
>> {
>> ...
>> }
>>
>> --
>>
>> Martin Honnen --- MVP XML
>> http://JavaScript.FAQTs.com/
>>



Reply With Quote
Sponsored Links
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 01:41 PM.
Style Developed by Epic Designz