471,594 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

problem with xml:lang

OJO
Hello microsoft.public.dotnet.xml!

I need to parse some 'jabber xml' (www.jabber.org). I opted for using
System.Xml.XmxDocument. The sample 'jabber xml' goes here:

<message xmlns='jabber:client' fr********@server.com/user1'
xml:lang='pl' type='groupchat' to*******@server.com/res'>
<body xmlns:xml='http://www.w3.org/XML/1998/namespace'>
MESSAGE TEXT
</body>
<x xmlns='jabber:x:delay' fr********@server.com' stamp='20040714T18:17:10'>
ch**@server.com
</x>
</message>

The problem is, that when I try:

doc.LoadXml(xml); // doc is a XmlDocument and xml is a string containing
above code

I get exception: "Namespace qualifiers beginning with 'xml' are reserved
and cannot be used in user-specified namespaces [line and column number
here]"

I also trid to add xml declaration:

doc.LoadXml("<?xml version='1.0' encoding='utf-8' ?>" + xml)

but with the same result.

I'm sure the xml is valid, because IE, VS, and Firefox
(http://www.mozilla.org/products/firefox/) find it valid.

I've been searching web (using google and msdn) for two days, but with
no results.

Mayby there is any way to overcome this problem? Or mayby there is some
other way to parser and validate xml i .net?

I'll be thankful for any information.

Sorry for my English - I'm still learning...

OJO
Nov 12 '05 #1
5 4032
OJO wrote:
I need to parse some 'jabber xml' (www.jabber.org). I opted for using
System.Xml.XmxDocument. The sample 'jabber xml' goes here:

<message xmlns='jabber:client' fr********@server.com/user1'
xml:lang='pl' type='groupchat' to*******@server.com/res'>
<body xmlns:xml='http://www.w3.org/XML/1998/namespace'>
xmlns:xml='http://www.w3.org/XML/1998/namespace' is the problem. This is
one piece of incompatibility brought to XML by XML namespaces. According
to original XML namespaces spec:

"The prefix xml is by definition bound to the namespace name
http://www.w3.org/XML/1998/namespace."
[http://www.w3.org/TR/REC-xml-names/#nsc-NSDeclared]

Apparently Microsoft's interpretation is "nobody can use xml as
namespace prefix, because it's bound by definition". We can see that
this interpretation is consistently implemented in all versions of MSXML
as well as in .NET.

Btw, recently XML Namespaces 1.1 clarified things a bit:
"The prefix xml is by definition bound to the namespace name
http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared,
and MUST NOT be undeclared or bound to any other namespace name."
[http://www.w3.org/TR/2004/REC-xml-na.../#xmlReserved]

But AFAIK Microsoft currently has no plans to support XML 1.1/ XML
Namespaces 1.1.
I'm sure the xml is valid, because IE, VS, and Firefox
(http://www.mozilla.org/products/firefox/) find it valid.

Are you sure about IE? My IE barfs at it:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error
and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------

The namespace prefix is not allowed to start with the reserved string
"xml". Error processing resource 'file:///D:/projects...

<body xmlns:xml='http://www.w3.org/XML/1998/namespace'>
------^

So the only workareound is probably to remove
"xmlns:xml='http://www.w3.org/XML/1998/namespace'" substring from the
document before parsing.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
OJO
Oleg Tkachenko [MVP] wrote:

xmlns:xml='http://www.w3.org/XML/1998/namespace' is the problem. This is
Thank, you. I though it was about xml:lang.

Are you sure about IE? My IE barfs at it:

You're right, i tested many lines of xml, and bogged down. Sorry.
So the only workareound is probably to remove
"xmlns:xml='http://www.w3.org/XML/1998/namespace'" substring from the
document before parsing.


Could you provide concrete example in c# or vb.net? I don't think it's
very smart to use string.Replace. Note that there might occur " instead
of ', and I'm not sure about URL (if it may be diffrent).

TIA

OJO
Nov 12 '05 #3
OJO wrote:
Could you provide concrete example in c# or vb.net? I don't think it's
very smart to use string.Replace. Note that there might occur " instead
of ', and I'm not sure about URL (if it may be diffrent).


The URL and th eprefix are always "http://www.w3.org/XML/1998/namespace"
and "xml". You may want to use regexp here. You need a pattern something
like

xmlns:xml\s*=\s*["']http://www.w3.org/XML/1998/namespace["']

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
OJO
Oleg Tkachenko [MVP] wrote:
The URL and th eprefix are always "http://www.w3.org/XML/1998/namespace"
and "xml". You may want to use regexp here. You need a pattern something
like

xmlns:xml\s*=\s*["']http://www.w3.org/XML/1998/namespace["']


Thank you, it helped me very much, but I'm afraid of it a little. What
about the situation when xmlns:xml... isn't param of tag, but simple
text? I know it isn't very likely, but not impossbie. I can't lose
valuable information it that way.

Thank you again.

OJO
Nov 12 '05 #5
OJO wrote:
Thank you, it helped me very much, but I'm afraid of it a little. What
about the situation when xmlns:xml... isn't param of tag, but simple
text? I know it isn't very likely, but not impossbie. I can't lose
valuable information it that way.


Yeah, I don't like it either. Should be a cleaner solution, but I fail
to see it right now.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Rafa³ | last post: by
reply views Thread by Martin Silar | last post: by
8 posts views Thread by Demon News | last post: by
6 posts views Thread by MONROUX philippe | last post: by
12 posts views Thread by Andreas Prilop | last post: by
8 posts views Thread by bitong | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

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.