Re: Cannot find root element in XML file
- From: TT (Tom Tempelaere) <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
- Date: Fri, 25 Aug 2006 02:43:02 -0700
Hi John,
"John Saunders" wrote:
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
wrote in message news:8BC434B4-CCE7-43CD-81D2-611DF074BC63@xxxxxxxxxxxxxxxx
Martin,
"Martin Honnen" wrote:
TT (Tom Tempelaere) wrote:
They don't work because from what I understood I only needed the
namespace
thingy for querying the root node. The nodes in the XML file aren't
qualified
so why would I have to qualify them to look them up?
You have not even bothered to show the contents of the root element but
your root element has
<IncidentDefinitions xmlns="http://tempuri.org/XMLSchema.xsd"
which means any child or descendant elements are in that namespace too
unless they have a redeclaration e.g.
<child xmlns="">
to have the element in no namespace or e.g.
<child xmlns="http://example.com/ns1">
to have the element in a different namespace.
See <http://www.w3.org/TR/REC-xml-names/#defaulting>
Oki, thanks for the information.
What I notice is that using the XPath expressions for the XML file where
the
root has an xmlns attribute, doesn't work for XML files where the root has
no
xmlns attribute (and vice versa). Is there any easy way to support both
using
the same XPath expressions? Or would I have to force my clients to either
add
the xmlns attribute or ommit it?
The presence or absence of the xmlns attribute mean different things. With
xmlns="urn:something", you're saying that all of the elements and attributes
in the document are in the namespace "urn:something". For example, in:
<root xmlns="urn:something" id="1"/>
"root" really means {urn:something}:root and "id" means {urn:something}:id.
When you're doing an XPath lookup for "root", you're looking for {}:root,
which is a totally different thing.
So, it's not that your clients have to either add or omit the xmlns
attribute - it's that they have to send you documents with the elements and
attributes in the correct namespace. If you've defined things so that your
elements aren't in a namespace, then they shouldn't send you elements which
are in a namespace. If you'ev defined things (properly), so that your
elements are in a namespace, then your clients have to send you documents
where the elements are in that namespace.
John
Thanks for that John. So the way I understand is that if I define my root in
XSD as follows:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="IncidentDefinitions">
...definitions etc...
</xs:schema>
Then this schema basically sais that any element and types that it defines
become members of the "http://tempuri.org/XMLSchema.xsd" namespace because of
the targetNamespace attribute of the xs:schema element? Or is it the xmlns
attribute (the value of both in the XSD is the same)?
And, that any XML document that is to conform with the schema, has to
attribute the root with xmlns attribute referring to that namespace?
Kind regards,
--
Tom Tempelaere.
.
- Follow-Ups:
- Re: Cannot find root element in XML file
- From: John Saunders
- Re: Cannot find root element in XML file
- References:
- Re: Cannot find root element in XML file
- From: Martin Honnen
- Re: Cannot find root element in XML file
- From: TT (Tom Tempelaere)
- Re: Cannot find root element in XML file
- From: Martin Honnen
- Re: Cannot find root element in XML file
- From: TT (Tom Tempelaere)
- Re: Cannot find root element in XML file
- From: Martin Honnen
- Re: Cannot find root element in XML file
- From: John Saunders
- Re: Cannot find root element in XML file
- Prev by Date: getting the value from text file to xml
- Next by Date: Re: getting the value from text file to xml
- Previous by thread: Re: Cannot find root element in XML file
- Next by thread: Re: Cannot find root element in XML file
- Index(es):
Relevant Pages
|
Loading