all groups > dotnet xml > july 2004 >
You're in the

dotnet xml

group:

problem with xml:lang



problem with xml:lang OJO
7/14/2004 11:35:31 PM
dotnet xml: 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' from='chat@server.com/user1'
xml:lang='pl' type='groupchat' to='user2@server.com/res'>
<body xmlns:xml='http://www.w3.org/XML/1998/namespace'>
MESSAGE TEXT
</body>
<x xmlns='jabber:x:delay' from='chat@server.com' stamp='20040714T18:17:10'>
chat@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...

Re: problem with xml:lang OJO
7/15/2004 10:37:22 AM
[quoted text, click to view]

Thank, you. I though it was about xml:lang.

[quoted text, click to view]

You're right, i tested many lines of xml, and bogged down. Sorry.

[quoted text, click to view]

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

Re: problem with xml:lang Oleg Tkachenko [MVP]
7/15/2004 10:58:37 AM
[quoted text, click to view]

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-names11-20040204/#xmlReserved]

But AFAIK Microsoft currently has no plans to support XML 1.1/ XML
Namespaces 1.1.

[quoted text, click to view]
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]
Re: problem with xml:lang Oleg Tkachenko [MVP]
7/15/2004 12:11:49 PM
[quoted text, click to view]

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]
Re: problem with xml:lang OJO
7/15/2004 4:37:54 PM
[quoted text, click to view]

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.

Re: problem with xml:lang Oleg Tkachenko [MVP]
7/15/2004 6:45:38 PM
[quoted text, click to view]

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

--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button