Cannot find root element in XML file

Hi all,

I created an XSD to define the structure of an XML file for my project. I 
made an XML file linked to the XSD using XmlSpy. The problem is that if I 
read the file using .NET XmlDocument and then query for the root element, the 
result is always null (1). However if I strip the root element of all 
attributes generated by XmlSpy, then there is no problem to find the root 
element with .NET XML classes (2).

(1) The XML for which querying root returns null:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<IncidentDefinitions xmlns="http://tempuri.org/XMLSchema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://tempuri.org/XMLSchema.xsd
C:/IncidentDefinitions.xsd">
  ....
</IncidentDefinitions>
[/code]

2/ The XML for which querying the root node succeeds:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<IncidentDefinitions>
  ....
</IncidentDefinitions>
[/code]

(3) The code in .NET to query for the root element:
[code]
XmlDocument xmlDoc;
xmlDoc.Load( xmlFileName );
XmlNode node = xmlDoc.SelectSingleNode( "IncidentDefinitions" );
[/code]

The thing is that I would very much like to be able to read in XML as in 
(1), to allow clients to validate their XML before publishing. For instance 
in XmlSpy I can verify the XML content to be valid before publishing it. Of 
course verification is no longer necessary once my program tries to read it, 
it is assumed that published XML should be valid.

What am I doing wrong in the first part? What can I do to allow both (1) and 
(2) in my .NET code?

Kind regards,
-- 
Tom Tempelaere.
0
Utf
8/22/2006 11:39:01 AM
dotnet.xml 7266 articles. 0 followers. Follow

16 Replies
1009 Views

Similar Articles

[PageSpeed] 40


TT (Tom Tempelaere) wrote:


> <IncidentDefinitions xmlns="http://tempuri.org/XMLSchema.xsd" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xsi:schemaLocation="http://tempuri.org/XMLSchema.xsd
> C:/IncidentDefinitions.xsd">
>   ....
> </IncidentDefinitions>


> (3) The code in .NET to query for the root element:
> [code]
> XmlDocument xmlDoc;
> xmlDoc.Load( xmlFileName );
> XmlNode node = xmlDoc.SelectSingleNode( "IncidentDefinitions" );

Well if you simply want to access the root element then
   xmlDoc.DocumentElement
will do whatever the name of the element is and whatever namespace that 
element has (where the namespace in your XML sample is the reason that 
your SelectSingleNode does not find the element).
Thus if you need to root element simply use
   XmlElement rootElement = xmlDoc.DocumentElement;
I don't think it makes sense to use XPath and SelectSingleNode to look 
for something the object model gives as a property.

As for SelectSingleNode to find an element with XPath in a certain 
namespace you would need e.g.
   XmlNamespaceManager namespaceManager = new 
XmlNamespaceManager(xmlDoc.NameTable);
   namespaceManager.AddNamespace("pf", "http://tempuri.org/XMLSchema.xsd");
   XmlElement rootElement = 
xmlDoc.SelectSingleNode("pf:IncidentDefinitions", namespaceManager) as 
XmlElement;




-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/22/2006 2:06:32 PM
Thanks Martin, that helped.

Kind regards,
-- 
Tom Tempelaere.

0
Utf
8/22/2006 3:37:02 PM
Hi Martin,

I may have cried Victory a little too early. None of your alternative 
suggestions works (I should have tested first). See inline for some comment.

"Martin Honnen" wrote:
> 
> TT (Tom Tempelaere) wrote:
> >
> > <IncidentDefinitions xmlns="http://tempuri.org/XMLSchema.xsd" 
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> > xsi:schemaLocation="http://tempuri.org/XMLSchema.xsd
> > C:/IncidentDefinitions.xsd">
> >   ....
> > </IncidentDefinitions>
> 
> > (3) The code in .NET to query for the root element:
> > [code]
> > XmlDocument xmlDoc;
> > xmlDoc.Load( xmlFileName );
> > XmlNode node = xmlDoc.SelectSingleNode( "IncidentDefinitions" );
> 
> Well if you simply want to access the root element then
>    xmlDoc.DocumentElement
> will do whatever the name of the element is and whatever namespace that 
> element has (where the namespace in your XML sample is the reason that 
> your SelectSingleNode does not find the element).
> Thus if you need to root element simply use
>    XmlElement rootElement = xmlDoc.DocumentElement;

Well to be honest I thought this would solve the problem, but it actually 
doesn't. If instead of querying the 'IncidentDefinitions' root element I use 
xmlDocument.DocumentElement I still have a problem: I can't find any other 
nodes that are in the document. 

> I don't think it makes sense to use XPath and SelectSingleNode to look 
> for something the object model gives as a property.
>
> As for SelectSingleNode to find an element with XPath in a certain 
> namespace you would need e.g.
>    XmlNamespaceManager namespaceManager = new 
> XmlNamespaceManager(xmlDoc.NameTable);
>    namespaceManager.AddNamespace("pf", "http://tempuri.org/XMLSchema.xsd");
>    XmlElement rootElement = 
> xmlDoc.SelectSingleNode("pf:IncidentDefinitions", namespaceManager) as 
> XmlElement;

Doesn't work either. It does return an element, but querying for any of the 
documents nodes fails.

It appears as though the attributes that are added by XmlSpy cannot be 
parsed correctly by .NET XML framework, or at least confuses it. Or maybe 
there is something else still that I'm not doing correct?

In the meanwhile I'll have to ask my clients to not publish any XML files 
with attributes for the root element.

> -- 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/

Kind regards,
-- 
Tom Tempelaere.

0
Utf
8/23/2006 1:21:02 PM
"TT (Tom Tempelaere)" wrote:
> > > <IncidentDefinitions xmlns="http://tempuri.org/XMLSchema.xsd" 
> > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> > > xsi:schemaLocation="http://tempuri.org/XMLSchema.xsd
> > > C:/IncidentDefinitions.xsd">
> > >   ....
> > > </IncidentDefinitions>
> > 
> > > (3) The code in .NET to query for the root element:
> > > [code]
> > > XmlDocument xmlDoc;
> > > xmlDoc.Load( xmlFileName );
> > > XmlNode node = xmlDoc.SelectSingleNode( "IncidentDefinitions" );

Maybe it isn't very obvious, but in the xsi:schemaLocation attribute there 
is a space between the two strings in it "http://tempuri.org/XMLSchema.xsd" 
and "C:/IncidentDefinitions.xsd". I thought that was not valid for XML to do, 
but XmlSpy generates it that way. Could that be the problem?

Kind regards,
Tom Tempelaere.
0
Utf
8/23/2006 1:26:02 PM

TT (Tom Tempelaere) wrote:


> Well to be honest I thought this would solve the problem, but it actually 
> doesn't. If instead of querying the 'IncidentDefinitions' root element I use 
> xmlDocument.DocumentElement I still have a problem: I can't find any other 
> nodes that are in the document. 

Well I have shown you to use an XmlNamespaceManager

>>As for SelectSingleNode to find an element with XPath in a certain 
>>namespace you would need e.g.
>>   XmlNamespaceManager namespaceManager = new 
>>XmlNamespaceManager(xmlDoc.NameTable);
>>   namespaceManager.AddNamespace("pf", "http://tempuri.org/XMLSchema.xsd");
>>   XmlElement rootElement = 
>>xmlDoc.SelectSingleNode("pf:IncidentDefinitions", namespaceManager) as 
>>XmlElement;


> Doesn't work either. It does return an element, but querying for any of the 
> documents nodes fails.

If those child or descendant elements are in the namespace 
http://tempuri.org/XMLSchema.xsd then you again need to use the 
namespace manager and you need to use the prefix in your XPath 
expressions, that is how XPath works. I don't understand why you claim 
the suggested ways don't work if you say they give you the element. If 
you then write additional code that does not do what you want then that 
additional code needs to be fixed obviously. Use that namespace manager, 
use that prefix in your XPath expressions to qualify element names (e.g. 
pf:elementname), pass the namespace manager to the SelectSingleNode or 
SelectNodes method calls and if you have the proper path then you will 
find nodes.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/23/2006 1:42:24 PM
"Martin Honnen" wrote:
> 
> TT (Tom Tempelaere) wrote:
> > Well to be honest I thought this would solve the problem, but it actually 
> > doesn't. If instead of querying the 'IncidentDefinitions' root element I use 
> > xmlDocument.DocumentElement I still have a problem: I can't find any other 
> > nodes that are in the document. 
> 
> Well I have shown you to use an XmlNamespaceManager
> 
> >>As for SelectSingleNode to find an element with XPath in a certain 
> >>namespace you would need e.g.
> >>   XmlNamespaceManager namespaceManager = new 
> >>XmlNamespaceManager(xmlDoc.NameTable);
> >>   namespaceManager.AddNamespace("pf", "http://tempuri.org/XMLSchema.xsd");
> >>   XmlElement rootElement = 
> >>xmlDoc.SelectSingleNode("pf:IncidentDefinitions", namespaceManager) as 
> >>XmlElement;
> 
> 
> > Doesn't work either. It does return an element, but querying for any of the 
> > documents nodes fails.
> 
> If those child or descendant elements are in the namespace 
> http://tempuri.org/XMLSchema.xsd then you again need to use the 
> namespace manager and you need to use the prefix in your XPath 
> expressions, that is how XPath works. I don't understand why you claim 
> the suggested ways don't work if you say they give you the element. 

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?

Makes me wonder how I support both types of XML files, those with attributed 
root and those without.

Anyway I don't really understand what it means: "If those child or 
descendant elements are in the namespace 
http://tempuri.org/XMLSchema.xsd...". I'm far from being an expert in XML 
(hence my questions) but I would say that the nodes that I defined in my 
schema aren't "child" or "descendant" elements in the namespace 
"http://tempuri.org/XMLSchema.xsd". Or am I just not seeing things correctly?

> If 
> you then write additional code that does not do what you want then that 
> additional code needs to be fixed obviously. Use that namespace manager, 
> use that prefix in your XPath expressions to qualify element names (e.g. 
> pf:elementname), pass the namespace manager to the SelectSingleNode or 
> SelectNodes method calls and if you have the proper path then you will 
> find nodes.

Well my code that reads in the XML works fine if the root node doesn't have 
the attributes, so my code isn't wrong per se. 

Anyway, since I'm too noob to understand your answers, I'll go the easy way. 
Away with those stupid attributes.

> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/

-- 
Tom Tempelaere.
0
Utf
8/23/2006 4:35:01 PM

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>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/23/2006 5:12:51 PM
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?

Another question since you seem to be an expert on XML and related stuff. 
What would you ask your clients to supply as XML files: with or without the 
xmlns attribute? I'm rather unaware of what is usually done because I have 
little experience in these matters.

> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/

Thanks,
-- 
Tom Tempelaere.
0
Utf
8/24/2006 3:57:01 PM
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_> 
wrote in message news:8BC434B4-CCE7-43CD-81D2-611DF074BC63@microsoft.com...
> 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


0
John
8/24/2006 5:38:56 PM
Hi John,

"John Saunders" wrote:

> "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_> 
> wrote in message news:8BC434B4-CCE7-43CD-81D2-611DF074BC63@microsoft.com...
> > 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.
0
Utf
8/25/2006 9:43:02 AM
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_> 
wrote in message news:A90D417D-0A0F-4893-B88C-BF66612B1596@microsoft.com...
> Hi John,
>
> "John Saunders" wrote:
>
>> "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
>> wrote in message 
>> news:8BC434B4-CCE7-43CD-81D2-611DF074BC63@microsoft.com...
>> > 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?

You've got it. It's the targetNamespace which defines these elements in that 
namespace. It's the xmlns on the insance document which specifies that those 
elements refer to the same ones you defined - which is what you probably had 
in mind.

Also, keep in mind that there is more than one way to place instance 
elements into your namespace. For instance, <IncidentDefinitions 
xmlns="http://tempuri.org/XMLSchema.xsd"/> or <xxx:IncidentDefinitions 
xmlns:xxx="http://tempuri.org/XMLSchema.xsd"/> or <yyy:IncidentDefinitions 
xmlns:yyy="http://tempuri.org/XMLSchema.xsd"/> are all the same thing.

John


0
John
8/25/2006 9:58:11 AM
Thanks John and Martin for helping me understand things.

Kind regards,
--
Tom Tempelaere.
0
Utf
8/25/2006 10:31:02 AM
Hi,

I have one final question about these namespaces, hope you don't mind.

What if my XSD root read like:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
 .....
</xs:schema>

Does this schema also imply that the elements of an XML document based on 
that XSD are in a specific namespace? Or does this schema define elements 
that are in the empty namespace?

Kind regards,
-- 
Tom Tempelaere.

0
Utf
8/25/2006 11:11:02 AM
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_> 
wrote in message news:915DEF42-214A-438F-86EC-8305D80CA242@microsoft.com...
> Hi,
>
> I have one final question about these namespaces, hope you don't mind.
>
> What if my XSD root read like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> .....
> </xs:schema>
>
> Does this schema also imply that the elements of an XML document based on
> that XSD are in a specific namespace? Or does this schema define elements
> that are in the empty namespace?

Since it doesn't have a target namespace, the elements are defined in the 
empty namespace, which is generally not a good idea.

John


0
John
8/25/2006 3:41:07 PM
"John Saunders" wrote:

> "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_> 
> wrote in message news:915DEF42-214A-438F-86EC-8305D80CA242@microsoft.com...
> > Hi,
> >
> > I have one final question about these namespaces, hope you don't mind.
> >
> > What if my XSD root read like:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> > elementFormDefault="qualified" attributeFormDefault="unqualified">
> > .....
> > </xs:schema>
> >
> > Does this schema also imply that the elements of an XML document based on
> > that XSD are in a specific namespace? Or does this schema define elements
> > that are in the empty namespace?
> 
> Since it doesn't have a target namespace, the elements are defined in the 
> empty namespace, which is generally not a good idea.
> 
> John

Hi,

Oki thanks. I will have to read some more about why those namespaces are 
really necessary and in what circumstances.

Kind regards,
-- 
Tom Tempelaere.
0
Utf
8/25/2006 4:31:02 PM
"TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_> 
wrote in message news:CCA0728D-BA00-4539-A8D4-25172C1820D2@microsoft.com...
> "John Saunders" wrote:
>
>> "TT (Tom Tempelaere)" <_|\|_0$P@|/\|titi____AThotmailD.Tcom|/\|@P$0_|\|_>
>> wrote in message 
>> news:915DEF42-214A-438F-86EC-8305D80CA242@microsoft.com...
>> > Hi,
>> >
>> > I have one final question about these namespaces, hope you don't mind.
>> >
>> > What if my XSD root read like:
>> >
>> > <?xml version="1.0" encoding="UTF-8"?>
>> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> > elementFormDefault="qualified" attributeFormDefault="unqualified">
>> > .....
>> > </xs:schema>
>> >
>> > Does this schema also imply that the elements of an XML document based 
>> > on
>> > that XSD are in a specific namespace? Or does this schema define 
>> > elements
>> > that are in the empty namespace?
>>
>> Since it doesn't have a target namespace, the elements are defined in the
>> empty namespace, which is generally not a good idea.
>>
>> John
>
> Hi,
>
> Oki thanks. I will have to read some more about why those namespaces are
> really necessary and in what circumstances.

This part is simple.

If you will only ever be dealing with one XML vocabulary, and if these 
simple XML files you're dealing with will never be used anywhere else, then 
don't use namespaces.

But the whole point of XML is universality. XML is data and program and 
everything in between. XML can be consumed by XML, sent to web services, and 
all sorts of things you've never considered. As a crazy example, I have code 
which manipulates XML to produce a schema which is then made into part of 
the WSDL for a web service which is then sent blocks of XML as parameters!

Namespaces simply allow my node called "root" to be different from your node 
called "root", and in fact your "root" today, for application "a" to be 
different from your own node "root", in application "b", tomorrow. They are 
a:root and b:root, and they are totally different things.


John


0
John
8/25/2006 9:29:44 PM
Reply:

Similar Artilces:

PLEASE HELP! How to extract information in inbox/sentbox into a text file #2
Can any one tell me how to extract the information of new mails in m inbox/sentbox, including the sender name, message subject and messag time, into a text file ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com ...

A code to import other xls data into one xls file
Hi there. Can anyone help me in creating a VB code in excel Module that imports data like file name;direct cost; and year from several xls spreadsheets [reports_1, reports_2, ...] (from different sheets and cells) into one spreadsheet [summary] into the following columns accordingly: (column 1 [file name]: file name; column 2 [direct cost]: dollar amounts, column 3 [year]: year)? i already have the code that pulls file names from the folder directory and pastes the data into column 1 [file name]. may be it will be easier to have the code refer to that column 1. Please note that t...

I need to compare 3 numbers and find the one in the middle
I have three numbers in a single row and would like to identify the middle number enter that number in another cell. Example: 1st # 2nd # 3rd # result 628 678 720 678 655 625 700 655 748 720 725 725 is there a function in excel that can do this? Thanks, Eddie Try =LARGE(A1:C1,2) VBA Noo -- VBA Noo ----------------------------------------------------------------------- VBA Noob's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3383 View this thread: http://www.excelforum.com/showthread.php?threadid=56811 fasteddie wrote.....

Find Duplicate names and delate
Dear experts, I have a small doubt could you clarify that??? That is I find duplicate name but I want to delete one name only, if I filter DUPLICATE….. both names are showing… 1. Select the range of data including the header. You need to have headers for these columns 2. From menu Data>Filter>Advanced Filter>Copy to another location 3. In 'copy to' specify the target cell and check 'Unique records only' 4. Click OK will give you the unique list -- Jacob "Find Duplicate names and delate" wrote: > Dear experts, > I have a small ...

Installation files
I bought Money 2006 Deluxe earlier this year after downloading the trial version online. Yesterday my computer crashed and I had to reinstall Windows. Is there any way I can get the files necessary to reinstall Money? Thanks. In microsoft.public.money, Kirill wrote: >I bought Money 2006 Deluxe earlier this year after downloading the trial >version online. Yesterday my computer crashed and I had to reinstall Windows. >Is there any way I can get the files necessary to reinstall Money? Thanks. You can download and install the Money 2006 trial version. When Money uses a file with ...

VS2005 XML Template?
I've done some researching on the net and I keep seeing references to an XML/XSLT Template in the New/Add Project dialog window, however I do not see such a template in the dialog window. I tried checking add/remove components after reinserting the VS2005 disc, but no mention of extra templates. I've also checked the Search Online Templates option, but nothing turns up. If anyone can guide me in the right direction, it'd be most appreciated! There are no Xml/Xslt templates for VS. You can create Xml or Xslt files using File | New | File and selecting Xml or Xslt file from the ...

Publisher cuts off text from word file that I am pasting into tex.
What does "Type your message here" mean to you? -- Ed Bennett - MVP Microsoft Publisher http://www.mvps.org/the_nerd/ Before reading this message, view the disclaimer: http://mvps.org/the_nerd/disclaim.htm Let me guess the question... You paste Word text into a Publisher text box and it doesn't fit. -- Mary Sauer MS MVP http://office.microsoft.com/ http://www.msauer.mvps.org/ news://msnews.microsoft.com "DeborahKB" <DeborahKB@discussions.microsoft.com> wrote in message news:F29CD723-545B-4A7C-8ACA-DD5092DCE101@microsoft.com... > Ooooooooh, Mary...

Excel files reporting read only
I have an issue where a user I provide support for is being told that a file that has not been opened for a couple of months is reporting as being locked for editing by the last user to save the file (in some cases these users no longer exist on our network). When you check the open files on the server, these files are not showing as open. If teh user clicks to close, and then immediatley re-opens the file it opens as normal. There are no temporary files in the folder that the files are located in and I have cleared the temp folders on the client and on the server. The user has full control...

Exporting to a text file
How to export an Access query to a text file without the column heading? The query consists of single column and is used to import to an accounting system. Thanks. Cannot be done with the built-in TransferText action / method. You'd need to open a text file via VBA code and write the query's records (one at a time) into that file. If interested, post back and I'll provide some sample code. -- Ken Snell <MS ACCESS MVP> "Paul" <paul_mak@shaw.ca> wrote in message news:O$MxJCPlHHA.1244@TK2MSFTNGP04.phx.gbl... > How to export an Access quer...

Finding a Median
I'm trying to write a query that will return a median for various values taken from a previous query. I've seen some suggestions in my searching, but I haven't been able to get them working. They are also all from before 2003 and refer to Access 97 and 2000. Has any functionality been added to 2003 for this? Or is there a non- code-based way to do it? I've seen it suggested to write a code to open the query, sort it, find the total number of records, divide it in half, then seek out the middle record using that value. I'm still very green when it comes to code, though...

Find a Value the first Time It Occurs
I have a row of values that shows the total cumulative number of sales of items by month. Occasionally, there may be no sales in a month for an item so the cumulative value would stay the same for more than one month. I want to select a number in the row the first time it occurs and not select it if it repeats. What are you wanting to do with the info? To return position (column number) of number 1234 within row 2: =MATCH(1234,2:2,0) A formula that signals it's the first occurence: =COUNTIF($A2:A2,A2)=1 This could be used in a helper row, or as a conditional format f...

Find/Replace in RichEdit 2.0
I'm using Windows ME and I've switched from RichEdit 1.0 to 2.0 for my CRichEditDoc/View application so that I can use the ITextDocument interface and can do things such as suspend/resume the Redo buffer. Problem is, now the Find/Replace dialogs don't seem to do anything. If I revert back to RichEdit 1.0 they do! What's going on? BUMP! adriangibbons@yahoo.co.uk (Adrian Gibbons) wrote in message news:<34a2acd5.0404130713.123dbaab@posting.google.com>... > I'm using Windows ME and I've switched from RichEdit 1.0 to 2.0 for my > CRichEditDoc/View application...

Problem in installing file system driver
Hi, I am not able to install my .sys file filter driver.I have written .inf file and while installing this inf file its not giving any error also.Plz help me in solving this. my file filter driver file name is : *****************Here is My .inf file ******************************* [Version] Signature="$Chicago$" Class=MyDriver ClassGuid={286E934F-962E-4e1c-9729-1F65205A094F} Provider=%ADITI% DriverVer=01/22/2004,1.11.1111 [ClassInstall32] Addreg=MyDriverReg [MyDriverReg] HKR,,,,%DisplayClassName% HKR,,Icon,,"-5" [Manufacturer] %ADITI%="Aditi" [SourceDisk...

Find (but not find)
My program takes a name from sheet3 goes to sheet1 to Find the name. If it cannot find name, how do you do an If/End to Exit Do while or find out if name has been founf? I have "On Error Resume Next" in program. Thanks again for all your help Gordon As ALWAYS, post your code for comments & suggestions. -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett1@austin.rr.com "Gordon" <gwelch1938@yahoo.com> wrote in message news:1184612089.486737.144020@n60g2000hse.googlegroups.com... > My program takes a name from sheet3 goes to sheet1 to Find the na...

Looking for a basic "duplicate file name finder" app.
Does anyone use a free duplicate file finder that they like? I know there are lots out there but when I went to download.com and searched, I got 800 hits. When I tried the "most popular" according to it's ratings, they turned out to be trial-ware. The most popular tool seems to do everything *but* find duplicate filenames. It wanted to "clean up my system". Thanks. -- Al Dykes News is something someone wants to suppress, everything else is advertising. - Lord Northcliffe, publisher of the Daily Mail http://www.softpedia.com/get/S...

Opening a form with cursor in a control filed
I have a form with a subform as reference. I only do data entry in 3 fields. I have set the tab control for field 1, 2 and 3, but when I click on add new record the cursor goes to the subform and and cannot tab out to the first field of the main form. I would like to set this up that on got focus the cursor is on the selected field and then tabs or move on enter to the next selected field in the tab order. The tab order in the main for is resetting to zero. Thanks Quinto -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200801/1 ...

Finding an event
Hello, I am developing an app that uses a single worksheet to enter data. When user double clicks a button, a new window (in same workbook) opens with a new sheet. My problem is that excel does not seem to have any events for close of window if there are multiple windows in a workbook. Can someone help Peter Peter, That triggers the Workbook_WindowActivate event, you can use that. HTH Bob "Peter Ostermann" wrote in message news:i9m5v8$7bv$02$1@news.t-online.com... Hello, I am developing an app that uses a single worksheet to enter data. When user double clicks a button...

link .pub files
I have produced a series of .pub files [Publisher 2003] for a book - each has illustrations, footnotes etc as separate text or picture boxes. I now want to put all the chapters into a new .pub file so that I can take the complete book to a printer - but I can't find a way to do this! Best 'fix' so far has been to save each chapter as a Word file and import that into a new .pub file. But that does not deal with the pictures, which all have to be re-inserted in the precisely correct position. there MUST be a better way! Or is it another problem with Publisher, like the inabi...

Find value in a column and insert rows above
The set up looks like this: ColU ColV ColW ColX Y N N N Y N N N N Y N N N N Y N N N Y N N N Y N N N Y N N N Y Y Columns will always be U through X and will always be sorted in this order. I need to find the first Y in each column and insert 2 rows above that row. On the blank row above the first Y, I need to highlight in yellow and put title in the first cell, such as New, Old, Existing, Deleted. Any help would be greatly appreciated. Thanks for your time, Dee If desired, send your file to my address below. I will only look if: 1. You send a copy of this ...

where to write temporary files?
hello experts, I am developing a software and I need to create a couple of temp files when the program is running. I need a piece of advice regarding the best place to put them: - Windows\temp directory - User directory - Program directory - ?? Needless to say, the directory must exist and the user must have the appropriate permissions. What are the good practices regarding this question ? Thanks Phil On Mon, 5 May 2008 08:43:18 -0700 (PDT), Phil <pbruyant@yahoo.com> wrote: >hello experts, >I am developing a software and I need to create a couple of temp files >when >the pr...

Signing XML documents
I am working to develop and application which will generate XML files. I would like to sign these documents at the time of creation to allow someone to verify them at a later date. What would be the best way to sign an XML document using ASP.NET. I have considered using the SIGNTOOL.EXE from Microsoft and simply use VBSCRIPT to use the command. Is there an simple and easy method from ASP.NET to apply a digital signature to the XML files. We plan to use an SSL certificate to sign the documents. Thanks! Have you taken a look at the classes in the System.Security.Cryptography.Xm...

cannot find database
I have an excel spreadsheet that is supposed to update a access db. Whenever I try to save the .xls I get an error stating cannot find db. Even when I open the db with access, I get the error and the db opens anyway?????? This only happens on 2 out of 20 pc's and I cannot figure out why???????? Thanks ...

Unable to log into file
I read that I could not sign up for Experian if I updated a 2004 file. So I created a new 2005 with my current passport login/password. After I created my Experian account, I then went and removed online access to that file (2005). However when I try to log back into my original file, I enter the password and it begins to log in and then the password just goes blank with no error message. I have verified that no accounts are online, I have removed the passport login using Password Manager from my new 2005 account, but I still can not log back into my updated 2004 original money f...

SBS 2008 File Transfer
Greetings, I am running SBS2008 on an HP ML370 G6 server. I have a total of 6 Hard drives (2 SAS drives, and 4 SATA drives). The 2 SAS drives are raided together with Raid 0 and SBS2008 is running off that raid. The 4 SATA drives are are raided into 2 drives with Raid 0 as well (2 sata drives / drive). The server now has 3 seperate drives (C,D,E). My problem is that when copying large files from C to D drive or anywhere D to E drive or any drive combination, speeds are fast, no problem. When copying files to an external USB drive, it takes hours, 16 hours for 175GIG of...

Sum if Condition is Equal in Range Date and find column
I want to make a sum if Range is a week number and if style is Equal to CONC-92 or CONC-45 Week# 49 Week# 50 CONC-92= 27 CONC-92= 30 CONC-45= 27 CONC-45= 30 Datas are in a pivot table and... Pivot table looks like this: Date CONC-92 CONC-45 CONC-92 CONC-45 12/7 5 5 10 10 12/8 2 2 10 10 12/9 5 5 10 10 12/10 5 5 10 10 please help -- Lorenzo Díaz Cad Technician ...