473,830 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Instantiate a Schema from a string?

An XML Schema document is an XML document, and (in .net) an XML document can
be loaded from a string. Is there a simple way to load an XML Schema document
from a string? The closest I can see is to wrap the string in a stream and
pass the stream to the constructor.

Stepping back further, I might want to load the XML Schema into an XML
document object and validate it to be sure it's a valid XML Schema before I
try to instantiate the Schema object. Shouldn't this simple?

Basically, whether it's a silly thing to do or not, I want to accept a
string, validate it as a Schema, and use it to validate some other string.
Oct 3 '06 #1
2 1653


PIEBALD wrote:
An XML Schema document is an XML document, and (in .net) an XML document can
be loaded from a string. Is there a simple way to load an XML Schema document
from a string? The closest I can see is to wrap the string in a stream and
pass the stream to the constructor.

You do not need a stream, you can simply read in the string with a
StringReader <http://msdn2.microsoft .com/en-us/library/z042k543.aspxe. g.

XmlReaderSettin gs readerSettings = new XmlReaderSettin gs();
readerSettings. ValidationType = ValidationType. Schema;
readerSettings. ValidationEvent Handler += delegate (object sender,
ValidationEvent Args vargs) {
Console.WriteLi ne("{0}: {1}", vargs.Severity, vargs.Message);
};
readerSettings. Schemas.Add(nul l, XmlReader.Creat e(new
StringReader(st ringWithSchemaM arkup));

// now use readerSettings for validating reader
using (XmlReader reader = XmlReader.Creat e(new
StringReader(st ringWithXMLMark up), readerSettings) ) {
reader.Read();
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 3 '06 #2
You do not need a stream, you can simply read in the string with a
StringReader <http://msdn2.microsoft .com/en-us/library/z042k543.aspxe. g.
My mistake, I was under the impression that StringReader derived from Stream.

I was essentially hoping the details of instantiating the StringReader could
be hidden.

But now I see the difficulty, It's the XmlReader.Creat e(), if given a string
it must be a URI, not a document. Very well, thank you for the sample.
Oct 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2398
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could generate any of the specific instances. sample schema one: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="base">
1
2064
by: eXavier | last post by:
Hi, I need to validate XML fragment against XSD schema. The main issue is that xml fragment does not contain refrence to schema, but I want to force the validation against the schema I have in XmlSchema object. The scenario is as follows: I have string fragment;
4
5060
by: A. Gonzalez | last post by:
Hi everyone, Does anyone know how to instantiate, or create an XML document file (either using DOM or Readers) from an XML schema (xsd) file? I'm trying to develop an application that can handle different xml doc structures, but at the same time I need to create these documents, even if there's no content. So I was planning to drive it with schema files (xsd), but I haven't figured out from looking at the .net SOM how to create the...
1
6413
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i reference this wsdl in .NET it seems to do it fine, yet there are no objects to reference except RateQuoteBeanService. In the WSDL it looks like there should be getRateQuote, and QUOTEREQUEST, etc.
5
5407
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in separate files for ease of maintainability. These schemas are all part of the same namespace. When defining a web service that access more than one of these entities, the wsdl file generated by BEA contains multiple schema elements with the same...
1
1136
by: Sebastian Stein | last post by:
Hi, I now have a valid XML Schema (XSD) file. I wonder if there is a free tool to instantiate it. Of course I can use any text editor, but it would be much nicer to have a tool doing it for me. Just in case there is no such free tool, is there a free tool that I can check a document (XML) if it conforms to the schema?
1
19080
by: Mikus Sleiners | last post by:
I have a task to create xml document from c# code. I have example of that document should look like and also a xml schema. I wonder if i can use this xml schema somehow ? This is schema: <?xml version="1.0"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
4494
by: JMD | last post by:
A set of xsd files has been working fine for us at this site, but now it gives *intermittent* errors for someone at a different cite (who is consuming the code we are producing). Most of the time it works fine. Occasionally it gives an error in the schema compiler: "System.Xml.Schema.XmlSchemaException: Wildcard '##other' allows element 'Page', and causes the content model to become ambiguous. A content model must be formed such that...
0
2039
by: =?Utf-8?B?TGFzdGJ1aWxkZXJz?= | last post by:
Hi all, I have a weird problem which has been causing me a headache for the last two days. I have to dynamicly generate a schema in memory and load it into a dataset in memory to be returned for further use. To create the schema I am using the XMLSchema classes and the result is the
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10487
jinu1996
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...
0
10202
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7745
isladogs
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...
0
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
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...
2
3958
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
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...

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.