473,748 Members | 5,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Relax NG:table

I am learning Relax NG. The problem is that I cannot figure
out how to make a schema for a table.
In my case I would like to make a table with any name of child
elements (columns) but columns should have the same number of
child elements (cell). Say this file is valid
<table>
<column>
<cell/>
<cell/>
</column>
<column>
<cell/>
<cell/>
</column>
<table/>

but this one is not
<table>
<column>
<cell/>
<cell/>
</column>
<column>
<cell/>
</column>
<table/>

Thank you in advance.

Jan 31 '06 #1
7 2289
sl*******@gmail .com wrote:
I am learning Relax NG. The problem is that I cannot figure
out how to make a schema for a table.
In my case I would like to make a table with any name of child
elements (columns) but columns should have the same number of
child elements (cell). Say this file is valid


That's not expressible as a regular tree language, so Relax NG can't
express it either. In fact, no schema language that I know of can
express it.

Soren
Jan 31 '06 #2
You can use Schematron embedded rules for that. See below a full
sample:

<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:sch="http ://www.ascc.net/xml/schematron">
<start>
<element name="table">
<oneOrMore>
<element name="column">
<sch:pattern name="Check to have the same number of cells in
each column" id="cells">
<sch:rule context="column ">
<sch:assert test="count(../column[1]/cell) =
count(cell)">Th e number of cells in this
column should be the same as in the firtst column,
expected <sch:value-of
select="count(. ./column[1]/cell)"/> but got
<sch:value-of select="count(c ell)"/>.
</sch:assert>
</sch:rule>
</sch:pattern>
<oneOrMore>
<element name="cell">
<empty/>
</element>
</oneOrMore>
</element>
</oneOrMore>
</element>
</start>
</grammar>

On your second document (after you make it wellformed) you will get:

The number of cells in this column should be the same as in the firtst
column, expected 2 but got 1 . (count(../column[1]/cell) = count(cell))

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Feb 1 '06 #3
Soren Kuula wrote:
sl*******@gmail .com wrote:
I am learning Relax NG. The problem is that I cannot figure
out how to make a schema for a table.
In my case I would like to make a table with any name of child
elements (columns) but columns should have the same number of
child elements (cell). Say this file is valid

That's not expressible as a regular tree language, so Relax NG can't
express it either. In fact, no schema language that I know of can
express it.

Soren


hi,

you should consider an alternate schema technology, such as Active Schema :

the schema :
=============== ======= schema.asl
<?xml version="1.0" encoding="iso-8859-1" ?>
<asl:active-schema
xmlns:xcl="http ://www.inria.fr/xml/active-tags/xcl"
xmlns:asl="http ://www.inria.fr/xml/active-schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema-datatypes"
target=""
<asl:element name="test" root="always">
<asl:sequence >
<asl:element ref-elem="table" min-occurs="0"
max-occurs="unbound ed"/>
</asl:sequence>
</asl:element>

<asl:element name="table">
<asl:sequence >
<asl:element ref-elem="column" min-occurs="1"
max-occurs="unbound ed"/>
</asl:sequence>
</asl:element>

<asl:element name="column">
<asl:sequence >
<xcl:if test="{ asl:element()/preceding-sibling::column }">
<xcl:then>
<asl:element ref-elem="cell" min-occurs="{
$asl:max-occurs }" max-occurs="{ count( asl:element()/../column[1]/cell
) }"/>
</xcl:then>
<xcl:else>
<asl:element ref-elem="cell" min-occurs="1"
max-occurs="unbound ed"/>
</xcl:else>
</xcl:if>
</asl:sequence>
</asl:element>

</asl:active-schema>
=============== ======
as you might guess, the Active Schema Language differs slightly from
other schema technologies : most things that are usually hard-coded in
the schema can be defined contextually
-boundaries can be computed dynamically
-content models can also be computed dynamically
-you can mix declarative sentences with imperative instructions
-the specification defines only 20 tags
-and much more...

notice that unlike schematron, ASL computes content models, which allows
tools such as editors to predict which element is allowed ; schematron
is not predictive, it can only warn that a rule has not been followed
AFTER the user has made the mistake, for example by inserting an element
that is not allowed

the datas :
=============== ====== datas.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<test>

<!--good-->
<table>
<column>
<cell/>
<cell/>
</column>
<column>
<cell/>
<cell/>
</column>
</table>
<table>
<column>
<cell/>
<cell/>
<cell/>
</column>
<column>
<cell/>
<cell/>
<cell/>
</column>
<column>
<cell/>
<cell/>
<cell/>
</column>
</table>

<!--bad-->
<table>
<column>
<cell/>
<cell/>
</column>
<column>
<cell/><!--cell missing-->
</column>
</table>
<table>
<column>
<cell/>
<cell/>
</column>
<column>
<cell/>
<cell/>
</column>
<column>
<cell/>
<cell/>
<cell/><!--too much cell-->
</column>
<column>
<cell/><!--cell missing-->
</column>
</table>
<table>
<!--no column ???-->
<cell/><!--oops-->
<cell/><!--oops-->
</table>

</test>
=============== ===========

the Active Sheet which validates the datas with the schema :
=============== =============== active-sheet.xcl
<?xml version="1.0" encoding="iso-8859-1"?>
<xcl:active-sheet
xmlns:xcl="http ://www.inria.fr/xml/active-tags/xcl"
xmlns:asl="http ://www.inria.fr/xml/active-schema"


<xcl:parse name="datas" source="datas.x ml"/>
<asl:parse-schema name="schema" source="schema. asl"/>

<asl:validate schema="{ $schema }" node="{ $datas }" augment="yes"
deep="yes" report="report"/>

<xcl:for-each name="err" select="{ $report/* }">
<xcl:echo value="Error { name( value( $err/@reason-id ) ) }"/>
<xcl:echo value=" node : { value( $err/@path/@path ) }"/>
<xcl:echo value=" rule : { value(
$err/@rule-path/@rule-path ) }"/>
</xcl:for-each>

</xcl:active-sheet>
=============== ======
you see unusual XPath expressions above, because Active Tags allow to
use XPath on non-XML object, which is the case of "$err" : an object can
expose some properties as attributes, which value can be an object can
expose some properties as attributes, which explain why $err/@path/@path
is relevant

the output :
=============== ======
Error asl:elementExpe cted
node : {/test/table[3]/column[2]/}
rule :
{/asl:active-schema/asl:element[3]/asl:sequence/xcl:if/xcl:then/asl:element}
Error asl:noMoreConte ntAllowed
node : {/test/table[4]/column[3]/cell[3]}
rule : {/asl:active-schema/asl:element[3]}
Error asl:elementExpe cted
node : {/test/table[4]/column[4]/}
rule :
{/asl:active-schema/asl:element[3]/asl:sequence/xcl:if/xcl:then/asl:element}
Error asl:elementExpe cted
node : {/test/table[5]/cell[1]}
rule : {/asl:active-schema/asl:element[2]/asl:sequence/asl:element}
Error asl:noMoreConte ntAllowed
node : {/test/table[5]/cell[1]}
rule : {/asl:active-schema/asl:element[2]}
Error asl:noMoreConte ntAllowed
node : {/test/table[5]/cell[2]}
rule : {/asl:active-schema/asl:element[2]}

=============== =======
the detailed specification :
http://disc.inria.fr/perso/philippe....ve-schema.html

the tool that implement all that stuff :
http://reflex.gforge.inria.fr/

you can download RefleX freely and run the given Active Sheet to check
the XML datas with the Active Schema
--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
Feb 1 '06 #4
Thank you everyone.
And I am sorry about the typo in the example.

I actually use emacs nxml mode to create XML files by hands. nxml mode
uses RELAX NG and the sample given by George can be used for validation
(it is already very helpful for me). But it seems in this case it would
not be predictive (as Philippe pointed out).

I am wondering is there any editor or emacs mode based on Active
Schema?

Feb 2 '06 #5
sl*******@gmail .com wrote:
Thank you everyone.
And I am sorry about the typo in the example.

I actually use emacs nxml mode to create XML files by hands. nxml mode
uses RELAX NG and the sample given by George can be used for validation
(it is already very helpful for me). But it seems in this case it would
not be predictive (as Philippe pointed out).

I am wondering is there any editor or emacs mode based on Active
Schema?


sorry, not yet : it is somewhat experimental :)

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
Feb 2 '06 #6
Hmm, I do not understand what can be predicetd here. The column element
contains cell and that's all. Assumming you have a table with 2 columns
and each column with 3 cells. Now if you want to have 4 cells in each
column no matter where you start you will pass through an invalid state
so would you prefer to have no hints than to have cell offered as
possible entry inside column?

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Feb 2 '06 #7
This is an interesting remark : it seems preferable for an editor to
*suggest* rather than to *force* ; thus, the user would be allowed to
leave a valid state.

I thought that the first <column> could be taken as the model for the
rest of the <table>, but there is certainly a better strategy to compute
the boundaries :
-if there is a single <column>,
min-occurs=0 (or 1 ?)
max-occurs=unbounde d
-if there are several <column>s :
min-occurs=max(numb er of <cell>s in the other <column>s)
max-occurs=min(numb er of <cell>s in the other <column>s)
So, considering a <column>, the others are "the reference", and you are
*suggested* to converge, either by deleting or adding <cell>s, until all
the <column>s have the same number of <cell>s ; however, even if you are
not suggested to add a new <cell>, you are *allowed* to do so anyway.

This is strange because having min-occurs > max-occurs is possible ; for
the moment I was reporting this case as an error in the schema, but I
could reconsider this (maybe by reporting a warning instead), as it's
only a case where some conditions are not met and can be corrected in
many actions.

I'm still convinced that defining content models dynamically increases
significantly the expressiveness of schemata. This is the power of
Active Schema.

George Bina wrote:
Hmm, I do not understand what can be predicetd here. The column element
contains cell and that's all. Assumming you have a table with 2 columns
and each column with 3 cells. Now if you want to have 4 cells in each
column no matter where you start you will pass through an invalid state
so would you prefer to have no hints than to have cell offered as
possible entry inside column?

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
Feb 2 '06 #8

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

Similar topics

1
2964
by: Erich Trowbridge | last post by:
Has anybody seen this tool? It is awesome. check out http://vw.vermeer.org/ . It's a php front end for large-scale syslog deployments. It makes managing syslog in large networks a snap. The idea is to fifo pipe network syslog into a MySQL database backend. The php scripts reference the database, and print stuff to the screen. My Info -> RH9.0 , MySQL 4.0.14, apache1.3.28 I have successfully gotten everything installed, compiled, etc....
5
5287
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table (table.ID is TestTable) On .aspx page: <HeaderTemplate> <asp:Table ID="TestTable" runat="Server" /> </HeaderTemplate>
7
10111
by: Jack | last post by:
Hello, <TABLE BORDER=1 CELLSPACING=0> <TR> <TH> <style="WIDTH=10"> ABC </TH> <TH> <style="WIDTH=500"> DEF
47
18898
by: Matt Kruse | last post by:
http://www.mattkruse.com/temp/css_expressions.html One of the standard CSS questions is "how can I shade every other table row a different color with CSS?" The answers are usually 1) you can't (yet), 2) put a class on every other tr, or 3) use javascript to do the styling for you. Well, I've been playing the CSS expressions quite a bit lately and I've found a much simpler solution which works in IE5.5+, using "expressions". If
2
6681
by: Jen | last post by:
Trying to take one table in access and split it into multiple excel files(using an excel template); and then email based on email addresses in Table2; Of course, I would like to do all of this with minimum user-interface...If there is anyone out there that can help... please feel free to share!:) PS... Using MSOffice 2000 Example: Table1
1
10303
by: Robert Schuldenfrei | last post by:
Dear NG, I have successfully bound a combo box to a table when only one column was involved. I am trying to present the user with the primary key to an item-location table. The primary key involves two columns, loc_PartNo and loc_location. My method: GetItemLocListing() works fine and returns the DataTable that I instantiate to locTable. I can not get the combo box to display and select both parts of the Primary Key. To test the...
1
3269
by: Benny Ng | last post by:
Hi,All, Export Method: ------------------------------------------------------------------------- strFileNameExport = "Results" Response.Clear() Response.Buffer = True Response.ContentType ="application/vnd.ms-excel" 'application/msword
1
4924
by: stabbert | last post by:
We are on DB2 UDB 8.2.2 on AIX. I know this question has been asked many times on the ng but I am just not finding a real good answer. I need to be able to not only determine existing table data size and index size but also estimate for the future. I keep seeing info regarding using reorgchk and the such however my dba will not allow us developers to have access to the comands necessary such as runstats. How can a lowely developer such...
9
7713
by: NEWSGROUPS | last post by:
I have data in a table in an Access 2000 database that needs to be exported to a formatted text file. For instance, the first field is an account number that is formatted in the table as text and is 8 characters long. This field needs to be exported as pic(15) padded in the front with 0's (zeros). The next field an ID name that is 15 characters that needs to be exported as pic(20) padded with trailing spaces. There are about 5 fields in...
0
8826
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,...
1
9316
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
9241
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
8239
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
6793
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
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
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
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
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.