473,417 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

define static content in XML-Schema / Relax NG

I am using XML Schema for quite a while but haven't written a single
line of Relax NG yet.

For what I know, I cannot define static content within an XML Schema.
For example, I have the following structure:

<colors>
<color>green</color>
<color>red</color>
</colors>

With XML-Schema, I can say colors should have to elements of type
color, and color can contain "green" or "red". But I cannot say that
the content has to be exactly as posted above. Is this correct?

Is there a way to do this in Relax NG?

I need it for more levels than just one. I want to be able to define a
whole XML-Document within the "Schema", so only a document with exactly
that content will be valid.

Jul 23 '05 #1
5 1732
If you don't care about the order in which colors appear, you can do this in
xml schema. Depending on how complex your schema is, you might be able to
to something like this for more than just one level.

<?xml version="1.0" encoding="utf-8" ?>

<xs:schema targetNamespace="foo"

elementFormDefault="qualified"

xmlns="foo"

xmlns:foo="foo"

xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:simpleType name="colorType">

<xs:restriction base="xs:string">

<xs:enumeration value="green"/>

<xs:enumeration value="red"/>

</xs:restriction>

</xs:simpleType>

<xs:element name="colors">

<xs:complexType>

<xs:sequence>

<xs:element name="color" type="colorType" minOccurs="2"
maxOccurs="2"/>

</xs:sequence>

</xs:complexType>

<xs:unique name="uniqueColors">

<xs:selector xpath="foo:color"/>

<xs:field xpath="."/>

</xs:unique>

</xs:element>

</xs:schema>
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<mh******@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
I am using XML Schema for quite a while but haven't written a single
line of Relax NG yet.

For what I know, I cannot define static content within an XML Schema.
For example, I have the following structure:

<colors>
<color>green</color>
<color>red</color>
</colors>

With XML-Schema, I can say colors should have to elements of type
color, and color can contain "green" or "red". But I cannot say that
the content has to be exactly as posted above. Is this correct?

Is there a way to do this in Relax NG?

I need it for more levels than just one. I want to be able to define a
whole XML-Document within the "Schema", so only a document with exactly
that content will be valid.

Jul 26 '05 #2
Thanks for your answer but the order does play an important role in
this project. I already found out that with Relax NG it is possible to
define the order and therefore static content. Even though it is also
quite "talkative" so you cannot just write how it has to look.

Jul 30 '05 #3
I don't get it. If the exact content is predetermined, what information does
the document convey?

If a large section of a document must be boilerplate for content from a
specific source, why not make a schema and documents such that the boilerplate
content is excluded, then use XSLT to insert the boilerplate content after the
initial validation is done?

Finally, if inserting the content fixed later is not an option, you could use
a combination of XML Schema and Schematron since Schematron makes it easy to
validate data content. In the case below, you just first assert that, in the
context of "/colors", "color[1]='green' and color[2]='red'"

On 22 Jul 2005 09:24:41 -0700, mh******@gmail.com wrote:
I am using XML Schema for quite a while but haven't written a single
line of Relax NG yet.

For what I know, I cannot define static content within an XML Schema.
For example, I have the following structure:

<colors>
<color>green</color>
<color>red</color>
</colors>

With XML-Schema, I can say colors should have to elements of type
color, and color can contain "green" or "red". But I cannot say that
the content has to be exactly as posted above. Is this correct?

Is there a way to do this in Relax NG?

I need it for more levels than just one. I want to be able to define a
whole XML-Document within the "Schema", so only a document with exactly
that content will be valid.


Jul 31 '05 #4
It is (normally) not the whole document that is predetermined but I
want the possibility to predetermine large parts of a document.
Furthermore, I want to use the same mechanism (i.e. W3C XML Schema) to
validate. In addition to validation I want to use this schema (or
better call it template) to generate a valid XML file without further
information.
I use a modified version of W3C Schema now, i have an element called
"template" where I can predetermine fixed parts and also include
dynamic elements again. Looks like that:
....
<xs:complexType name="colorsType">
<xc:template>
<color>red</color>
<color>blue</color>
<color xs:type="colorType" xs:minOccurs="0" xs:maxOccurs="4" />
</xc:template>
</xs:complexType>
....

This is ok for my purpose and it works as an "XML constructor" as I
provide initial values for regular pattern values for example. But I
have to write my own validator which is quite a lot of work. You
schematron suggestion is nice for validation but doesn't work for
creation. I need it all in one file.

Aug 2 '05 #5
On 2 Aug 2005 03:30:50 -0700, mh******@gmail.com wrote:
It is (normally) not the whole document that is predetermined but I
want the possibility to predetermine large parts of a document.
Furthermore, I want to use the same mechanism (i.e. W3C XML Schema) to
validate. In addition to validation I want to use this schema (or
better call it template) to generate a valid XML file without further
information.
I use a modified version of W3C Schema now, i have an element called
"template" where I can predetermine fixed parts and also include
dynamic elements again. Looks like that:
...
<xs:complexType name="colorsType">
<xc:template>
<color>red</color>
<color>blue</color>
<color xs:type="colorType" xs:minOccurs="0" xs:maxOccurs="4" />
</xc:template>
</xs:complexType>
...

This is ok for my purpose and it works as an "XML constructor" as I
provide initial values for regular pattern values for example. But I
have to write my own validator which is quite a lot of work. You
schematron suggestion is nice for validation but doesn't work for
creation. I need it all in one file.


No XML tools I know of were really built to do what you're describing in
regard to performing both generation and validation. If you can make it work
at all, it's going to be a terrible kludge.
Aug 2 '05 #6

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

Similar topics

1
by: Joshua McCulloch | last post by:
I have setup Apache 2.0.50 and JBoss 3.2.5 using mod_jk2. My application is defined to operate in the root context (http://servername/) by creating a WEB-INF/jboss-web.xml I am serving static...
1
by: dSchwartz | last post by:
I am creating a totally adminable news system in asp.net (C#, SQL server). what i want to accomplish is allow multiple news templates to be read by an admin area. heres how it works...
1
by: A Amitkashaw | last post by:
Hello, As a new guy to XML I'm stuck on (what I perceive as) a trickey problem. I'm defining the element as so: <!ELEMENT brains (#PCDATA)> Within this element I have to be able to use HTML...
10
by: Fred | last post by:
Hello, After looking at various CMS tools, either server- (Drupal, Pivot, etc.) or desktop-based (CityDesk, Cute Site Builder), it occured to me that I really didn't need something that...
8
by: ad | last post by:
I have studied buisness layer in http://beta.asp.net/QUICKSTART/util/srcview.aspx?path=~/aspnet/samples/data/GridViewObject.src It separate Author class to Author and AuthorComponent If I...
5
by: | last post by:
Hi, How long do webservice objects live for? In particular, if i have static variables filled with data from a static constructor in a webservice, how long will that data persist? thxs
4
by: BA | last post by:
Hello, I have a very strange code behavior that I cannot make heads or tails of: I have c# code being executed in BizTalk assemblies which is acting very strangely. In my BizTalk process I...
23
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
1
by: Tarscher | last post by:
Hi all, I need to build XML files. Some XML files are almost entirely static containing some dynamic content. An example is a file I need to build that contains about 100 line that are static....
5
by: Timothy Madden | last post by:
Hy static members of non-integral type need to be declared in the class, but defined (and constructed or initialized) outside the class. Like this class SystemName { public:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...
0
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
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,...

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.