I am trying to validate an XML file that does not contain any xmlns: namespace attribute against a
predefined XSD schema.
I should think this would be easy to do, since there must be far more "unqualifie d" XML files out
there than there are ones that include a namespace reference.
Unfortunately, as I am coming to hate about all things XML, the easy things are extraordinarily
difficult and/or subtle.
I know how to create a schema collection dynamically and validate qualified XML files against it.
But I can't figure out the "no namespace in the XML file" situation (other than rewriting the XML
file to include an xmlns: attribute at the root, but that's too ugly to think about).
I tried, among many other things:
FileStream xsdStream = File.OpenRead(s chemaFile);
XmlTextReader xsdTR = new XmlTextReader(x sdStream);
XmlSchemaCollec tion schemaColl = new XmlSchemaCollec tion();
schemaColl.Add( "http://tempuri.org/finance.xsd", xsdTR);
FileStream xmlStream = File.OpenRead(f ileName);
XmlTextReader xmlTR = new XmlTextReader(x mlStream);
XmlValidatingRe ader xmlReader = new XmlValidatingRe ader(xmlTR);
xmlReader.Valid ationType = ValidationType. Schema;
xmlReader.Schem as.Add(schemaCo ll);
xmlReader.Valid ationEventHandl er += new ValidationEvent Handler(xmlRead er_ValidationEv entHandler);
XmlNamespaceMan ager theNSM = new XmlNamespaceMan ager(xmlTR.Name Table);
theNSM.AddNames pace(String.Emp ty, "http://tempuri.org/finance.xsd");
but that doesn't work, blowing up on the root element of the XML file, complaining that it can't
find schema information for the unqualified root element name.
So how the heck do I validate an XML file that has no namespace attributes???
- Mark 1 4174
Okay, I win the bozo award today.
It turns out three is a simple answer, but it's not in the code; it's in the XSD file. Stripping out
all the specific namespace references in the XSD file, and then using String.Empty as the target
namespace in the code, lets me validate "unqualifie d" XML files.
- Mark
On Tue, 09 Dec 2003 21:25:47 -0800, Mark Olbert <ma**@arcabama. com> wrote: I am trying to validate an XML file that does not contain any xmlns: namespace attribute against a predefined XSD schema.
I should think this would be easy to do, since there must be far more "unqualifie d" XML files out there than there are ones that include a namespace reference.
Unfortunatel y, as I am coming to hate about all things XML, the easy things are extraordinarily difficult and/or subtle.
I know how to create a schema collection dynamically and validate qualified XML files against it. But I can't figure out the "no namespace in the XML file" situation (other than rewriting the XML file to include an xmlns: attribute at the root, but that's too ugly to think about).
I tried, among many other things:
FileStream xsdStream = File.OpenRead(s chemaFile); XmlTextReade r xsdTR = new XmlTextReader(x sdStream); XmlSchemaColle ction schemaColl = new XmlSchemaCollec tion(); schemaColl.Add ("http://tempuri.org/finance.xsd", xsdTR);
FileStream xmlStream = File.OpenRead(f ileName); XmlTextReade r xmlTR = new XmlTextReader(x mlStream); XmlValidatingR eader xmlReader = new XmlValidatingRe ader(xmlTR); xmlReader.Vali dationType = ValidationType. Schema; xmlReader.Sche mas.Add(schemaC oll); xmlReader.Vali dationEventHand ler += new ValidationEvent Handler(xmlRead er_ValidationEv entHandler);
XmlNamespaceMa nager theNSM = new XmlNamespaceMan ager(xmlTR.Name Table); theNSM.AddName space(String.Em pty, "http://tempuri.org/finance.xsd");
but that doesn't work, blowing up on the root element of the XML file, complaining that it can't find schema information for the unqualified root element name.
So how the heck do I validate an XML file that has no namespace attributes???
- Mark This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Iain |
last post by:
I've got a system which takes an XML file, translates it into an update gram
and then loads it into my database with SQLXML3 (all in dot net).
But it's fragile. And the SQLXML 3 error reporting is not absolutely
wonderful.
So what I want to do is to validate it before I upload it.
When I try and do this I get MILLIONS of errors (well lots) complaining
about elements like ROOT which are part of the
|
by: Adam Child |
last post by:
Hi All,
I'm trying to validate an xml document. I'm having trouble setting the
default namespace of the xml document. If I hard encode the namespace
in the xml file then everything works fine. But I can't do this
because it breaks our old tools which validate the xml to a dtd (error
saying the dtd doens't allow xmlns attribute on the root element). So
I'm trying to add the default namespace to the xml file by code. As
follows:
|
by: Ryan |
last post by:
I have a very complex XDR schema that uses namespaces:
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:b="urn:schemas-microsoft-com:BizTalkServer"
xmlns:d="urn:schemas-microsoft-com:datatypes"
Do I need to build a custom validator in order to validate XML documents
against this schema? How does the XML parser know how to validate against
the extra namespaces?
|
by: Shailendra Batham |
last post by:
hi guys
I need your suggestions / opinion for doing this the right way.
I have a XML and a Schema for the same
What I want is when its validated against the schema, it should give custom errors saying what happened and where......
is it possible to do that ?
for eg. if the Attribute is missing or invalid in the following element <Watch ID="999d999">
|
by: A |
last post by:
Hi all!
I would like to ask you guys regarding validating an xml document against a
dtd file...
I'm not quite familiar manipulating xml and I was assigned to do a program
that could document some stuff using the DocBook format.
Any articles that you might suggest, I would gladly appreciate it!
| |
by: Ian |
last post by:
I've inherited some xml that doesn't have a namespace and doesn't have a
reference to the schema. The schema doesn't have a targetNamespace attribute.
I'm trying to build a test tool, in C#, which will send the xml to the server
and then validate the response against the schema. When I try and do this I
get a "The attribute targetNamespace does not match the designated namespace
URI" error.
Here's a snippet of the validation code:
...
|
by: Chris Lieb |
last post by:
I have an XML Schema file that I know is correct becuase I currently
use it in a VB6 program to validate XML documents. Also, if I load an
XML file into VS2005 that is not valid against this schema, I get XML
errors (blue squigglies) in a few places, which indicates to me that I
should get validation errors while validating through code.
When I try to validate an invalid document, I never get any validation
errors. I have tried many...
|
by: Mark |
last post by:
Hi...
I've been trying the .Validate() method on the XmlDocument to validate some
xml against a schema, but one thing I noted was that unless the document
explicitly declares the schema as a default namespace, Validate() just lets
it slide through as a success.
Is there a way to Validate() either a) mandating against a particular
schema, or at the very least b) supplying a default namespace to be used even
when not explicitly declared?
|
by: =?Utf-8?B?Q29kZVJhem9y?= |
last post by:
I wrote a method to validate and xml file against a schema.
If the file does not conform to the schema, it throws an error. It works
fine except for one curious thing.
If I try to validate an XDocument (containing schema xml) against a schema
url, it validates successfully..... Has anyone ever seen this before or know
why it does this.
Here is the code:
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |