Steinar Bang | 29 Nov 19:46 2006
Picon
Picon

Starting with nxml

Platform: Intel Pentium M,
Ubuntu Dapper,
emacs21 21.4a-3ubuntu2,
nxml-mode 20041004-5
trang 20030619-4

I am a _long_ time psgml user that eventually will try the leap into
nxml. The reason is that I need context sensitive editing for an XML
format for which I have an XSD schema (the Maven2 POM format).

So I'm fumbling about trying to get started.

I started by trying to create a schema locator, from the description
here:
http://www.dpawson.co.uk/relaxng/nxml/schemaloc.html#d339e168

`C-h v rng-schema-locating-files RET' gives me:
rng-schema-locating-files's value is
("schemas.xml" "/usr/share/emacs/site-lisp/nxml-mode/schema/schemas.xml")

So I did `C-x C-f schema.xml RET' in the same directory as the pom.xml
file that is to be edited. nxml gave the minibuffer message "Using
vacuous schema". I pasted in the example in the above URL, ie.
<?xml version="1.0"?>
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
<namespace ns="http://www.w3.org/1999/xhtml" uri="xhtml.rnc"/>
<documentElement localName="book" uri="docbook.rnc"/>
</locatingRules>

Then I deleted the <namespace> and <documentElement> elements, and
tried creating a new element. I tried `C-c C-e' to see if that would
give me the list of available elements (that's the psgml binding for
the same... who reads manuals...? :-) ).

That didn't work, so I did `C-h b' to see if there was an
nxml-insert-element command or something similar. The only commands
with "insert" in them, are:
C-c C-u nxml-insert-named-char
C-c C-x nxml-insert-xml-declaration

Some more browsing on Dave's Q&A seemed to indicate that `C-RET' was
the correct command (nxml-complete). But this command just reports
"Cannot complete in this context".

So is the problem that it can't find the schema? Or is this the wrong
command? Or am I trying an insert in the wrong place? Or does the
insert command have a problem with empty elements?

I don't think it is a missing schema, because the show schema location
command, reports
"Using schema /usr/share/emacs/site-lisp/nxml-mode/schema/locate.rnc"

Perhaps it's the wrong command? It seems to be a command to complete
_something_, but how do I know what to complete at this stage....?

Ah... if I type a `<' and _then_ `C-RET' I get a list of whatever can
be inserted at point, which is (probably) the allowed tags. And to
insert attributes I type a space and then `C-RET' again. To complete
an attribute value I type " followed by a space. `C-RET' again gives
me the possibility to insert a new attribute. And typing / and >
closes the element (there seemed to be no magic here).

This works after a fashion. But I prefer the psgml way of `C-e',
select the element, and then respond to prompts for required
attributes, followed by `C-c +' commands to insert other attributes.

Perhaps I'll get used to this way in time? Or perhaps there is a more
psgml-like mode of operation that I haven't discovered yet? (12 years
takes a lot of unlearning...)

Ok, so on to the schema. I've now created a schema.xml file that
resides in the same directory as the pom.xml file, that looks like
this:
<?xml version="1.0"?>
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
<namespace ns="http://maven.apache.org/POM/4.0.0" uri="maven.rnc" />
</locatingRules>

This based on a pom.xml header looking like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

Next is to give trang a look. Hm... doesn't look like it supports XSD
schema as an input schema...?
http://www.thaiopensource.com/relaxng/trang.html

Or has things happened since James dropped it?

Doesn't look that way, when looking at the man page of the Ubuntu
(debian?) deb package. It has XSD as an output format, but not as an
input format.

Hm... unless I can convert the maven2 XSD schema to an RNG schema, I
might as well roll back to good old psgml. Is there something else I
can use? Or is there a maven2 POM XML RNG schema around?

Ok. From the bottom of http://www.thaiopensource.com/nxml-mode/
I found rngconv. The procedure to use, was:

- download rngconv.zip from
https://msv.dev.java.net/servlets/ProjectDocumentList?folderID=101

- unzip rngconv.zip. It will create the directory rngconv-20060319/

- go to the rngconv-20060319/ directory, and type the following
commands:
wget http://maven.apache.org/maven-v4_0_0.xsd
java -jar rngconv.jar maven-v4_0_0.xsd >maven.rng
trang maven.rng maven.rnc

- then move maven.rnc to whereever the schemas.xml file resides
(currently the same directory as the top level pom.xml file of the
project I'm working on)

So now I appearently have a working schema.

I get an error message from the xsi:schemaLocation attribute.
Does nxml support namespaces? Does anyone know what magic is needed
to do so?

Does anyone have a best practice for setting up my own RNG schema
location? I won't do it tonight. Now it's time for actually _using_
that schema on the pom.xml file(s)...:-)

__._,_.___
SPONSORED LINKS
New business?

Get new customers.

List your web site

in Yahoo! Search.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
Dave Pawson | 29 Nov 21:21 2006
Picon

Re: Starting with nxml

On 29/11/06, Steinar Bang <sb <at> dod.no> wrote:
> Platform: Intel Pentium M,
> Ubuntu Dapper,
> emacs21 21.4a-3ubuntu2,
> nxml-mode 20041004-5
> trang 20030619-4
>
> I am a _long_ time psgml user that eventually will try the leap into
> nxml. The reason is that I need context sensitive editing for an XML
> format for which I have an XSD schema

James came from Relax to relax NG.
nxml-mode works (once you read the manual :-) with the .rnc
format of a relax ng schema.
XSD is the [insert bad language] cousin of relax-NG

If you only have the xsd,
go dig out rngconv from the sun downloads.

It tries to convert XSD to rng format.
Trang, from JC, converts from rng to XSD if needed.

It may work on your schema, it may not.
Either way, take a look at Eric's book on relax ng, available on line
but well worth buying.
Before you have had your first headache with xsd, you'll be happy
with relax NG.

Then you can convert the xsd into relax ng!

I've associated F9 with 'associate schema' to make it easier.

HTH DaveP

--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

__._,_.___
SPONSORED LINKS
Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
Michael(tm) Smith | 30 Nov 09:27 2006

Re: Starting with nxml

Steinar Bang <sb <at> dod.no>, 2006-11-29 19:46 +0100:

> So now I appearently have a working schema.
>
> I get an error message from the xsi:schemaLocation attribute.

Do you get an error because the particular file you're editing
contains an an xsi:schemaLocation instance, or do you just get an
error when nxml is parsing the schema (even when editing a file
that doesn't contain an xsi:schemaLocation)?

> Does nxml support namespaces? Does anyone know what magic is needed
> to do so?

nxml fully supports namespaces. No magic needed.

> Does anyone have a best practice for setting up my own RNG schema
> location?

If you're keeping your schema under version control, then I guess
one good way would be put it into whatever directory tree you keep
anything similar that you've got under version control (custom
DTDs, stylesheet customizations) and just point your
locating-rules file (e.g., schemas.xml) file to that.

--Mike

__._,_.___
SPONSORED LINKS
Need traffic?

Drive customers

With search ads

on Yahoo!

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
Steinar Bang | 30 Nov 09:54 2006
Picon
Picon

Re: Starting with nxml

>>>>> "Michael(tm) Smith" <smith <at> xml-doc.org>:

> Do you get an error because the particular file you're editing
> contains an an xsi:schemaLocation instance, or do you just get an
> error when nxml is parsing the schema (even when editing a file that
> doesn't contain an xsi:schemaLocation)?

I get the error because the file contains an xsi:schemaLocation
instance.

> nxml fully supports namespaces. No magic needed.

Do I need a schema that allows using a schemaLocation attribute in the
"http://www.w3.org/2001/XMLSchema-instance" namespace, in any element
in any namespace?

If so, I have no idea how to go about it.

Or should I hack the RNG schema I've created from an XSD schema using
rngconv, to allow the "xsi:schemaLocation" attribute on the top level
attribute?

Thanx!

__._,_.___
SPONSORED LINKS
Ads on Yahoo!

Learn more now.

Reach customers

searching for you.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
Steinar Bang | 30 Nov 09:49 2006
Picon
Picon

Re: Starting with nxml

>>>>> "Dave Pawson" <dave.pawson <at> gmail.com>:

> James came from Relax to relax NG. nxml-mode works (once you read
> the manual :-) with the .rnc format of a relax ng schema. XSD is
> the [insert bad language] cousin of relax-NG

> If you only have the xsd,
> go dig out rngconv from the sun downloads.

If you read to the bottom. You will see that's what I did. :-)

I need to think out loud when I'm doing stuff, so the message was
mostly me thinking to myself. But since I'd written it, and since
this list has been awfully quiet except for spam, I thought I might as
well give it a relevant message. :-)

__._,_.___
SPONSORED LINKS
Ads on Yahoo!

Learn more now.

Reach customers

searching for you.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
Florent Georges | 30 Nov 12:55 2006
Picon

Re: Re: Starting with nxml

Steinar Bang wrote:

Hi

> I get the error because the file contains an xsi:schemaLocation
> instance.

This attribute has to be explicitelly allowed in RNG grammars. You
can dig the archives for similar discussions. But I wonder if an
editing tool like nXML would have to permit the XSI attributes on
elements (for example if the grammar is translated from WXS), and maybe
have some support for them (completion for schema paths, completion for
types, etc.).

Regards,

--drkm





__________________________________________________________
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com

__._,_.___
SPONSORED LINKS
Ads on Yahoo!

Learn more now.

Reach customers

searching for you.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
Steinar Bang | 30 Nov 20:59 2006
Picon
Picon

Re: Starting with nxml

>>>>> Florent Georges <darkman_spam <at> yahoo.fr>:

> Steinar Bang wrote:
> Hi

>> I get the error because the file contains an xsi:schemaLocation
>> instance.

> This attribute has to be explicitelly allowed in RNG grammars.

I tried changing
<element name="project">
<interleave>
...
to
<element name="project">
<attribute>
<anyName/>
</attribute>
<interleave>
...

in the generated RNG schema, and then used trang to translate it into,
| element project {
attribute * { text },

But that wasn't enough.

> You can dig the archives for similar discussions. But I wonder if
> an editing tool like nXML would have to permit the XSI attributes on
> elements (for example if the grammar is translated from WXS), and
> maybe have some support for them (completion for schema paths,
> completion for types, etc.).

Here's an earlier thread on this list:
http://comments.gmane.org/gmane.emacs.nxml.general/998

Norm Walsh suggests using a wrapper grammar to add the xsi:
attributes. That's probably a good idea, but I'll try modifying the
grammar first to see if I can make it work... hm... changing the
attribute declaration to:
| element project {
attribute xsi:schemaLocation { text },
gave me the error message
File mode specification error: (error "Undefined prefix xsi at position 136 in /media/sda8/bangste/p4/depot/ccr/MAIN/maven.rnc")

Ok I changed (half-guessing, and using nxml to expand what's allowed)
the attribute declaration in the maven.rng file to look like this:
<element name="project">
<attribute>
<name ns="http://www.w3.org/2001/XMLSchema-instance">schemaLocation</name>
</attribute>
...

Then ran the schema through trang to get the following in maven.rnc:
default namespace = "http://maven.apache.org/POM/4.0.0"
namespace ns1 = "http://www.w3.org/2001/XMLSchema-instance"

start =
notAllowed
| element project {
attribute ns1:schemaLocation { text },
(element parent {
...

And that's enough to make the Maven POM files validate. Thanx!

I guess the next step will be to figure out what's meant by an
extension grammar, but for now this quick hack works for me.

Thanx again!

__._,_.___
SPONSORED LINKS
Ads on Yahoo!

Learn more now.

Reach customers

searching for you.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___

Gmane