473,511 Members | 16,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Relative XSD path

Hi guys,
I want to validate my xml by xsd schema. But in the xsd file I have RELATIVE
includes to the others xsd files that located in ..\ directory for the main
xsd.
Could you provide me code example that makes such a validation. All the
examples I found in google doesn't work.

Thanks a lot,
Aleksey
Feb 11 '08 #1
8 4603
What environment? asp.net? standard exe? etc?

If I recall, this should simply work (I'll run a quick test in a
moment to check) - however, it isn't hard to roll a custom XmlResolver
if you want to take control of where nested xsd come from; I use such
to pull my xsd from a resource file, for example.

Marc
Feb 11 '08 #2
I work in winforms environment.
I have main xsd that includes another in the next way:
<xs:include schemaLocation="..\MessageHeader.xsd"/>

Would you please send me your test code, that will resolve me the problem?

Thanks a lot,
Aleksey

"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
What environment? asp.net? standard exe? etc?

If I recall, this should simply work (I'll run a quick test in a moment to
check) - however, it isn't hard to roll a custom XmlResolver if you want
to take control of where nested xsd come from; I use such to pull my xsd
from a resource file, for example.

Marc

Feb 11 '08 #3
Try swapping the slash; the following works fine for me:

<xs:include schemaLocation="../Inner.xsd"/>

Let me know how you get on; I have a working console exe that works
fine with this approach, but I don't want to swamp you with xsd, xml
and cs unless the above fails ;-p

Marc
Feb 11 '08 #4
No it doesn't help :(
Still when I call
reader = XmlReader.Create( new StringReader( xml ), settings );

it fails with the next exception:

System.NullReferenceException: Object reference not set to an instance of an
object
Would you please provide me your test code, so I'll check what don't I do
right?

Thank you a lot for your help!!!
Aleksey

"Marc Gravell" <ma**********@gmail.comwrote in message
news:OP**************@TK2MSFTNGP04.phx.gbl...
Try swapping the slash; the following works fine for me:

<xs:include schemaLocation="../Inner.xsd"/>

Let me know how you get on; I have a working console exe that works fine
with this approach, but I don't want to swamp you with xsd, xml and cs
unless the above fails ;-p

Marc

Feb 11 '08 #5
I have (where there is also a Foo/Inner.xsd, included as per the
previous post); my "Oops" handler just writes a message to the console
to verify that my xml has been processed correctly (some valid, some
invalid):

XmlSchemaSet schema;
using(XmlReader reader =
XmlReader.Create("Foo/Bar/Outer.xsd")) {
schema = new XmlSchemaSet();
schema.Add(XmlSchema.Read(reader, Oops));
schema.Compile();
}
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas = schema;
settings.ValidationEventHandler += Oops;
settings.ValidationType = ValidationType.Schema;
using (XmlReader reader = XmlReader.Create("Sample.xml",
settings)) {
while (reader.Read()) { }
}

Marc
Feb 11 '08 #6
Thanks a lot, Marc!
It works now.
The problem was the next: I had pretty the same code with one defferance
that I used in StreamReader instead of XmlReader in the first "using"
statement.

Thank you a lot once again!
Aleksey
"Marc Gravell" <ma**********@gmail.comwrote in message
news:e6**************@TK2MSFTNGP02.phx.gbl...
>I have (where there is also a Foo/Inner.xsd, included as per the previous
post); my "Oops" handler just writes a message to the console to verify
that my xml has been processed correctly (some valid, some invalid):

XmlSchemaSet schema;
using(XmlReader reader = XmlReader.Create("Foo/Bar/Outer.xsd"))
{
schema = new XmlSchemaSet();
schema.Add(XmlSchema.Read(reader, Oops));
schema.Compile();
}
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas = schema;
settings.ValidationEventHandler += Oops;
settings.ValidationType = ValidationType.Schema;
using (XmlReader reader = XmlReader.Create("Sample.xml",
settings)) {
while (reader.Read()) { }
}

Marc

Feb 11 '08 #7
No problem; I can reproduce what you are seeing (StreamReader
failing); at a guess, perhaps the StreamReader doesn't have as much
clue where the original source location is, so it can't use
XmlResolver to find related files...

Interesting; I learn't something there (don't use StreamReader here
;-p) - so thanks for that.

Cheers,

Marc
Feb 11 '08 #8
(for completeness, this is the XmlReader.BaseURI property; there is
nothing equivalent for raw streams - plus you've gotta love the
consistent casing [URI vs Uri] and return type [System.String vs
System.Uri])

Marc
Feb 11 '08 #9

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

Similar topics

7
2770
by: Doug | last post by:
If I were to write an include with a relative path like include("../conf/config.php"); What is the use? As far as I understand it, the path is relative to the first script that is called by...
5
4095
by: jason | last post by:
Can anyone help me find a solution to quickly working out relative paths to a folder in the root of my server... Although it easy when you go - say - two levels down: .../includes it...
7
78614
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
6
11740
by: openleren | last post by:
Hi all, how can I use a relative path in my web.config file for an Access db?: Instead of using <configuration> <appSettings> <add key="conAccess" value="microsoft.jet.oledb.4.0;data...
4
7844
by: Win, Pats | last post by:
I have a snippet of HTML that I inject into a number of pages throughout my Web site at runtime. My problem is that I'm not getting the image to appear in all documents into which this snippet is...
18
9423
by: Nak | last post by:
Hi there, Does anyone know what path the AssemblyKeyFile attribute is relative to? For example I currently have mine set to <Assembly: AssemblyKeyFile("..\NicksKey.snk")> Sometimes this...
8
2592
by: JJ | last post by:
I'm confused about paths. I have a functionn that uses the mappath method, which I think requires a virtual path (is that the same as a relative path?). But this doesn't always work as the...
15
6434
by: Lars Eighner | last post by:
Aside from the deaths of a few extra electrons to spell out the whole root relative path, is there any down side? It seems to me that theoretically it shouldn't make any difference, and it would...
6
2486
by: Royan | last post by:
Ok the problem is quite hard to explain, but i'll try to keep it as simple as i can. Imagine I have the following structure of my files and folders: /root/global.inc |__/files/foo.php...
0
1476
by: Gabriel Genellina | last post by:
En Sat, 18 Oct 2008 05:52:04 -0300, Stef Mientki <stef.mientki@gmail.com> escribió: Why don't you let the caller tell you its own location, using __file__? The above code is too much magic for...
0
7138
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...
0
7355
Oralloy
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,...
1
7081
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...
0
5668
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,...
1
5066
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...
0
4737
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...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
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...

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.