473,769 Members | 5,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1746
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"

elementFormDefa ult="qualified"

xmlns="foo"

xmlns:foo="foo"

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

<xs:simpleTyp e name="colorType ">

<xs:restricti on base="xs:string ">

<xs:enumerati on value="green"/>

<xs:enumerati on 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="uniqueCol ors">

<xs:selector xpath="foo:colo r"/>

<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******** *************@g 49g2000cwa.goog legroups.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:complexTy pe name="colorsTyp e">
<xc:template>
<color>red</color>
<color>blue</color>
<color xs:type="colorT ype" 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:complexTyp e name="colorsTyp e">
<xc:template>
<color>red</color>
<color>blue</color>
<color xs:type="colorT ype" 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
7609
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 files (with apache) from a directory off the file system, by setting the DirectoryRoot variable in httpd.conf. JBoss is working off a .WAR built from this directory. Is there any way to reference the unarchived files from Apache?
1
3594
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 (hopefully): an artist creates a news template (html file), drops it into a specific directory, now a client can choose that template and edit a certain number of fields. the artist has to be able to specify these fields in the template somehow, example:
1
2600
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 tags. XML being XML I can either define every single HTML tag as a child or try and find a quick way of doing it. I'd rather not have to define every single HTML tag that I
10
2340
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 sophisticated just to add navigation bars in each article on my site, and generate the home page with hyperlinks to each article. I figured all it took is a script that ... 1. takes each raw HTML article that the user has generated with the
8
1937
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 combine the two together into Author Class for convenience, like codes below: Is it ok to do that?
5
6279
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
2286
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 call a static method: public static string ValidateMessage(params...)
23
3920
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
1118
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. Somewhere in the middle I need to inject some dynamic XML lines. Someone has an idea on how to best solve this? With a template engine? Greets,
5
7240
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
9423
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
10043
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
9861
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
8869
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
7406
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
5298
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...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
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
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.