473,659 Members | 3,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Schemas, imports and namespaces

I'm a real XML novice, but my ultimate goal here is to get a workable schema
for the GEDCOM XML format as spec'ed out here:

http://www.familysearch.org/GEDCOM/GedXML60.pdf

It's a proposed XML format for genealogical records. They include a DTD in
the spec but sadly its incomplete in that the spec allows for "html"
(unlimited HTML or a subset they don't say) in certain elements to allow for
formatting. There is also a sample GEDCOM file in the spec with some
<html:BR /elements. There is no tag for "html:BR" in the DTD so it fails
on their included GEDCOM file.

So I have a few things to do. I want a schema, not a DTD and I want HTML to
be allowed in certain elements. An approximate schema I can produce by
using VS to change the DTD to a schema. The HTML part I have no idea how to
do. I would love to be able to say in the schema that the citation element
(to name one example) can have any tag from the "html" namespace but I don't
see how to do this. So I scaled back my expectations and decided to just
try to allow for <html:BR />. You can't declare this directly because XML
gets hung up on the namespace. I couldn't find anything that talked about
this in all the schema docs I looked at so I decided to let VS handle it for
me. I produced a schema from the GEDCOM XML file and it produced two xsd
files. One is the gedcom.xsd and one is a schema file which solely defines
<html:BR />. It also placed an import element in the gedcom.xsd file:

<xs:import namespace="http//:www.w3c.org/TR/REC-html40/" />

This does, in fact, seem to reference the file with html:BR defined,
although I fail to see how the resolution works. I mean, it seems to work
through the target namespace from the imported schema matching up with the
namespace named in the import statement and that, in turn matching up with
the xmlns attribute in the schema element, but I don't know how it finds the
html file to make these matches. It certainly works for me in VS and the
gedcom XML file with <html:BR /seems to validate properly according to the
VS XML editor. They (the base and html schemas) are in the same directory
which is the directory of my executable so I kind of figured that the
resolution was done by looking at every xsd file in the directory to see if
any have that namespace as a target and importing them if so. In any event,
since the XML editor was telling me that this file was valid with this
schema, I thought that was great, I'll definitely get it to work when I run
my simple program which, currently, simple reads the XML file into an
XmlDocument. Now, in order to test the schema in the editor, I have to
explicitly reference the filename with a noNamespaceSche maLocation attribute
in the root element of the XML file (is there some other way?). If I'm
running this on general GEDCOM files, obviously they're not going to
reference my schema file so I have to remove the explicit filename link
formed by the noNamespaceSche maLocation attribute and instead, load in the
schema manually and attempt to use it to validate like so:

XmlSchemaSet sc = new XmlSchemaSet();
sc.Add(null, "gedcom.xsd ");
XmlReaderSettin gs settings = new XmlReaderSettin gs();
settings.Valida tionType = ValidationType. Schema;
settings.Schema s = sc;
settings.Valida tionEventHandle r += new
ValidationEvent Handler(Validat ionCallBack);
XmlReader xrd = XmlReader.Creat e(strXmlFile, settings);
(_xdoc = new XmlDocument()). Load(xrd);

When I do this, it tells me that it can't load in the schema file because
html:BR is not declared so it would appear that my guess about the
resolution occuring because they were in the same directory is wrong - at
least when I'm doing this all programmaticall y.

So what do I need to do here to get it to do the import correctly? It
appears that importing is the only way to handle the html namespace since I
produced the schema from the GEDCOM file in another piece of software and it
also produced two files with one importing from the other.

Finally, and this is really a pure XML question: supposing I do get this to
work. That only allows me to use the html namespace in my base schema
declarations. In order to allow for all of HTML in certain elements as I'm
doing things now, that means I have to declare every HTML tag in each of the
elements I want to allow them in. Is that really what has to be done? Do I
have to put *all* potential HTML tags in my schema to declare them as legal?
Again, it would be *really* nice to just be able to say "anything from the
HTML namespace is legal here". Is there some good way of doing that? I
suppose I could just allow for some subset of HTML tags but it would be nice
to give an option where the user could just type in (or paste in) any HTML
he/she likes and I would store it mostly as a black box without ever
directly interpreting any of the contents but just passing them in to an
HTML viewer control.

Sorry for the long post. I don't know how to make it any more brief. If
you're still with me, thanks for any ideas you might have on this!

Darrell
Oct 30 '06 #1
2 3077
When you used the Visual Studio editor to produce a schema for your XML, it
produced one schema per namespace encountered in your file. Your file
contains an element in the 'html' namespace so it created a schema from that
namespace and imported its namespace into the parent schema. Internally the
Xml Editor has constructed a Xml Schema set itself and has added both of
these schemas to it. Since both schemas are in the set, it does not need an
explicit file location to fetch the imported schema from - it is already in
memory. But when you save these schema files out to disk, you should put a
schemaLocation attribute in the import statement in order for the imported
schema to be resolved when you later use them in another application. Like:

<xs:import namespace="http//:www.w3c.org/TR/REC-html40/"
schemaLocation= "HTMLSchema.xsd "/>

So you could either have an explicit location reference in your main schema
like above, or you could do what the Editor did: just load up all schema
files you need in a Xml Schema Set (not just gedcom.xsd) and the import will
resolve automatically since it is already in the set.

Regarding having to allow all HTML elements in your content models. You
could use an element wildcard (xsd:any). You can read up wildcards from
http://www.w3.org/TR/2004/PER-xmlsch...html#Wildcards
You could restrict your wildcard content to a namespace (like
http//:www.w3c.org/TR/REC-html40/) so you could only have element from the
html namespace to be allowed in that location. It is pretty useful to define
open content models like the one you need.

Thanks.
"Darrell Plank" <ja******@msn.c omwrote in message
news:uH******** ********@TK2MSF TNGP04.phx.gbl. ..
I'm a real XML novice, but my ultimate goal here is to get a workable
schema for the GEDCOM XML format as spec'ed out here:

http://www.familysearch.org/GEDCOM/GedXML60.pdf

It's a proposed XML format for genealogical records. They include a DTD
in the spec but sadly its incomplete in that the spec allows for "html"
(unlimited HTML or a subset they don't say) in certain elements to allow
for formatting. There is also a sample GEDCOM file in the spec with some
<html:BR /elements. There is no tag for "html:BR" in the DTD so it
fails on their included GEDCOM file.

So I have a few things to do. I want a schema, not a DTD and I want HTML
to be allowed in certain elements. An approximate schema I can produce by
using VS to change the DTD to a schema. The HTML part I have no idea how
to do. I would love to be able to say in the schema that the citation
element (to name one example) can have any tag from the "html" namespace
but I don't see how to do this. So I scaled back my expectations and
decided to just try to allow for <html:BR />. You can't declare this
directly because XML gets hung up on the namespace. I couldn't find
anything that talked about this in all the schema docs I looked at so I
decided to let VS handle it for me. I produced a schema from the GEDCOM
XML file and it produced two xsd files. One is the gedcom.xsd and one is
a schema file which solely defines <html:BR />. It also placed an import
element in the gedcom.xsd file:

<xs:import namespace="http//:www.w3c.org/TR/REC-html40/" />

This does, in fact, seem to reference the file with html:BR defined,
although I fail to see how the resolution works. I mean, it seems to work
through the target namespace from the imported schema matching up with the
namespace named in the import statement and that, in turn matching up with
the xmlns attribute in the schema element, but I don't know how it finds
the html file to make these matches. It certainly works for me in VS and
the gedcom XML file with <html:BR /seems to validate properly according
to the VS XML editor. They (the base and html schemas) are in the same
directory which is the directory of my executable so I kind of figured
that the resolution was done by looking at every xsd file in the directory
to see if any have that namespace as a target and importing them if so.
In any event, since the XML editor was telling me that this file was valid
with this schema, I thought that was great, I'll definitely get it to work
when I run my simple program which, currently, simple reads the XML file
into an XmlDocument. Now, in order to test the schema in the editor, I
have to explicitly reference the filename with a noNamespaceSche maLocation
attribute in the root element of the XML file (is there some other way?).
If I'm running this on general GEDCOM files, obviously they're not going
to reference my schema file so I have to remove the explicit filename link
formed by the noNamespaceSche maLocation attribute and instead, load in
the schema manually and attempt to use it to validate like so:

XmlSchemaSet sc = new XmlSchemaSet();
sc.Add(null, "gedcom.xsd ");
XmlReaderSettin gs settings = new XmlReaderSettin gs();
settings.Valida tionType = ValidationType. Schema;
settings.Schema s = sc;
settings.Valida tionEventHandle r += new
ValidationEvent Handler(Validat ionCallBack);
XmlReader xrd = XmlReader.Creat e(strXmlFile, settings);
(_xdoc = new XmlDocument()). Load(xrd);

When I do this, it tells me that it can't load in the schema file because
html:BR is not declared so it would appear that my guess about the
resolution occuring because they were in the same directory is wrong - at
least when I'm doing this all programmaticall y.

So what do I need to do here to get it to do the import correctly? It
appears that importing is the only way to handle the html namespace since
I produced the schema from the GEDCOM file in another piece of software
and it also produced two files with one importing from the other.

Finally, and this is really a pure XML question: supposing I do get this
to work. That only allows me to use the html namespace in my base schema
declarations. In order to allow for all of HTML in certain elements as
I'm doing things now, that means I have to declare every HTML tag in each
of the elements I want to allow them in. Is that really what has to be
done? Do I have to put *all* potential HTML tags in my schema to declare
them as legal? Again, it would be *really* nice to just be able to say
"anything from the HTML namespace is legal here". Is there some good way
of doing that? I suppose I could just allow for some subset of HTML tags
but it would be nice to give an option where the user could just type in
(or paste in) any HTML he/she likes and I would store it mostly as a black
box without ever directly interpreting any of the contents but just
passing them in to an HTML viewer control.

Sorry for the long post. I don't know how to make it any more brief. If
you're still with me, thanks for any ideas you might have on this!

Darrell


Oct 30 '06 #2
Ah, Zafar, you are a lifesaver and I am such a rookie. This was precisely
the right information and solved all my problems. I have always been a bit
puzzled about namespace resolution which most of my books don't talk about
too much, but now I'm enlightened! I'm glad to learn about the wildcard.
Thank goodness you told me about it because I can't find it mentioned in a
single one of my four books on XML.

Thanks very much!

Darrell
Oct 30 '06 #3

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

Similar topics

6
1468
by: inerte | last post by:
Hello all! I need to build an XML file structure so a client can import data to one of our systems. Totally new to XML, I learned about Namespaces and DTD, and built a nice spec using them. Now I am trying to use XML Schemas to tell more about what kind of data are allowed on each element/attribute, but I can't understand how to mix Namespaces and Schemas. Can anyone give me tips, starting points, about how to specify the
0
937
by: Murali Inguva | last post by:
I have an xml. It was generated from different schemas. I want to know the namespaces and the schemas that are reffered in that XML. So that i can add the Namespaces and Schemas to the Namespace Manager and Validate them. How do i dothat. One more time in simple words. I had an xml. i want to know how do i know what
4
1677
by: anonymous | last post by:
When I use the schema collection to apply many schemas to one XML instance document, I get an error if I do not qualify every element with the appropriate namespace. Both the W3C site and this article (http://www.xfront.com/ZeroOneOrManyNamespaces.html) imply that I can submit an XML instance without having to qualify each element. How do I accomplish this while still using .Net & the
2
1807
by: Shapper | last post by:
Hello, In the main root of my web site together with my aspx and aspx.vb files I have the file global.vb. This file has a class with all the functions which are used in many aspx.vb files and it is like this: Imports System Namespace Global
19
1842
by: Tiraman | last post by:
Hi , I have an assembly that hold few class and few imports which are not used in all of the class's . so my question is when to use the "Imports XXX" And when to use this kind of statement Dim X as New System.XXX ....
0
1826
by: vihrao | last post by:
I am designing wsdl that uses multiple schemas. I can do this in two ways: 1) use multiple schema imports in one wsdl or 2) use multiple schema imports in to one common schema and then import a single common schema in the wsdl. The issue is complicated because I have several wsdls with several common and unique schemas. As an example serviceA_Ports.wsdl imports a commonServiceTypes.Xml, commonFaultTypes.xml, and serviceA.xml ...
0
1006
by: dlutz | last post by:
Good day to all -- I have been trying to load a dataset from XML based on a multi-level schema structure that uses <xsd:importtags to bring other schemas into the XML document context - Schema1 imports Schema2 which then imports Schema3. I have not been having much success. Based on the above experience, I have a couple of questions: 1) Can the Dataset class handle multi-level schemas as defined above? If not, thanks for your time.
0
220
by: mgoold2002 | last post by:
Hello. I'm new to using XML/HTML. I am trying to learn to validate xml sample docs against schemas. I have an XML and Schema file (.xsd) saved to my desktop. Below is my sample code, which is borrowed from the .NET help files. It blows up when I try to refererence a schema that is on my desktop. If you can, please correct my misunderstanding about referencing schemas, as evidenced in the below example. Am I attempting the...
6
2469
by: douglass_davis | last post by:
Is the whole System namespace automatically imported?
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
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
8748
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...
1
8531
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,...
0
7359
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
6181
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
5650
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
4175
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...
1
2754
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 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.