giving colours to tags its content with XPath

Are you missing a feature? Request it's implementation here.
muewi
Posts: 26
Joined: Wed Aug 24, 2005 10:47 am

giving colours to tags its content with XPath

Post by muewi » Fri Nov 10, 2006 6:30 pm

Hello,

for our linguistic annotation, it would be useful to have different colours for different tags. E.g. we have a <tok> element and we would like to have a different colour for the <clause> element. It also depends on the nesting level, so probably it would be nice to be able to use Xpath in order to define what tags get which colour.

Regards,
Frank

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Tue Nov 14, 2006 12:45 pm

Hello,

If you want different colors for <tok> and <clause> maybe they should be in different namespaces. If they are defined in different namespaces you can set different colors in Options -> Preferences -> Colors / Elements by Prefix. You can use this feature even for elements defined in the same namespace if you use a namespace prefix or no prefix with tok and other namespace prefix with clause. The color is set for a prefix not for a namespace.

Setting tag colors using XPath expressions may look nice but is not feasible in practice. The performance problems would be too big. When you edit a document it switches between well-formed state and not well-formed state very often and the syntax highlight should be changed from the editing location to the end of the document for each switch. Also the XPath expressions can be applied only on well-formed documents.


Regards,
Sorin

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

declare prefixes?

Post by xinelo » Wed Jan 31, 2007 2:58 pm

hi,

I also needed different colours for differnet sets of tags, so I used prefixes t and c. Now I've got <t:role> coloured as red and <c:role> coloured as magenta. That's fine.

However I want to update my DTD or my schema and I don't know how. Well, I can declare two elements t:role and c:role, but that's not what I want, as that means I would need to declare twice the elements I've got. Instead I need to declare the prefixes as prefixes.

Any suggestion as how I should do this?

Thanks a lot!
xinelo

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

Post by xinelo » Wed Jan 31, 2007 3:11 pm

I better add an excerpt of my code to help you see my problem:

<?xml version="1.0" encoding="UTF-8"?>
<!--<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="textosxml/hegischema.xsd">-->

<document xmlns:t="http://www.example.com/xmlns/target" xmlns:c="http://www.example.com/xmlns/cue">
<body>
<p><NC>Israel_NP 's_POS</NC><NC>foreign_JJ <t:role>minister_NN</t:role></NC><VC>said_VVD</VC><NC>today_NN</NC>that_IN<NC>Mahmoud_NP Abbas_NP</NC>,_,<NC>the_DT <c:role>president_NN</c:role></NC><PC>of_IN<NC>the_DT Palestinian_NP Authority_NP</NC></PC>,_,<VC>was_VBD</VC><NC>"_`` no_DT</NC><ADVC>longer_RBR</ADVC><ADJC>relevant_JJ</ADJC></p>
</body>
</document>

Notice that I include two namespaces in the root element. That gives me a well-formed document but not a valid document.

And this is my DTD:

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

<!ELEMENT document (body)>
<!ATTLIST document
xmlns CDATA "()">
<!ELEMENT body (p)>
<!ELEMENT p (NC,VC,ADVC,ADJC,PC)>
<!ELEMENT VC (#PCDATA)>
<!ELEMENT ADVC (#PCDATA)>
<!ELEMENT ADJC (#PCDATA)>
<!ELEMENT PC (#PCDATA)>
<!ELEMENT NC (#PCDATA|role)*>
<!ELEMENT role (#PCDATA)>

Any idea will be welcome!

xinelo

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

Post by xinelo » Wed Jan 31, 2007 3:12 pm

Sorry, please ignore the <!ATTLIST document
xmlns CDATA "()"> lines. Ups!

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: declare prefixes?

Post by sorin_ristache » Wed Jan 31, 2007 4:28 pm

Hello,
xinelo wrote:Well, I can declare two elements t:role and c:role, but that's not what I want, as that means I would need to declare twice the elements I've got. Instead I need to declare the prefixes as prefixes.

Any suggestion as how I should do this?
I think XML Schema is more appropriate here instead of DTD. XML Schema allows you to define the role element once and in the XML document based on the schema use any namespace prefixes together with the role element as you already did for the t and c prefixes in the XML document that you posted. In a DTD you have to define two distinct elements t:role and c:role.


Regards,
Sorin

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

Post by xinelo » Wed Jan 31, 2007 6:53 pm

Thanks Sorin,

But do I not need to declare the prefixes in the XML Schema?

I've created a valid XSD schema for the same XML file document I posted earlier (in fact it's the schema that I used before adding the prefixes). The only relevant change is in the root element, in which I included the prefixes.

Code: Select all

<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
[b] xmlns:t="http://www.example.com/xmlns/target" xmlns:c="http://www.example.com/xmlns/cue"[/b]
xsi:noNamespaceSchemaLocation="hegischema.xsd"
>
However there's also that xsi prefix which I can't remember for what it was. Anyway, I keep getting an error when I try to validate the XML file: t:role and c:role aren't valid elements. so it seems that the schema doesn't know c and t are prefixes. This is the error I get:

Description: cvc-complex-type.2.4.a: Invalid content was found starting with element 't:role'. One of '{generic, pron, name, role, demonym, title, entity, abbr}' is expected.
URL: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type.

Thank you again!
xinelo

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Thu Feb 01, 2007 4:02 pm

Hello,

No, you do not need to declare the prefixes in the XML Schema. You just need to define the role element in the right namespace. I see that in the XML document you want to use a role element from the "http://www.example.com/xmlns/target" namespace and also a role element from the "http://www.example.com/xmlns/cue" namespace. In this case you need to define the role element twice because they are 2 different elements, one in the first namespace and the other in the second namespace. The validation error means that in your XML Schema you did not define the role element to be in the "http://www.example.com/xmlns/target" namespace but you try to use it in the XML document with a prefix associated with this namespace.


Regards,
Sorin

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

Post by xinelo » Thu Feb 01, 2007 5:51 pm

Hi Sorin,

Thanks again for your kind reply.

I'm not too sure I understand what you're trying to tell me. I think I don't know enough (I'm not even sure I understand the concept of namespaces, despite having read about it a lot of times), but let's see. I've tried several things. And I've realized declare and define are not the same thing in this context either.
sorin wrote:I see that in the XML document you want to use a role element from the "http://www.example.com/xmlns/target" namespace and also a role element from the "http://www.example.com/xmlns/cue" namespace.
Well, not that I want to. It's just what I think I must do to be able to use prefixes :)
sorin wrote:In this case you need to define the role element twice because they are 2 different elements, one in the first namespace and the other in the second namespace.


If I do:

Code: Select all

	<xs:element name="role" xmlns:c="http://www.example.org/xmlns/cue">
<xs:complexType mixed="true">
<xs:attribute ref="gender"/>
</xs:complexType>
</xs:element>

<xs:element name="role" xmlns:t="http://www.example.com/xmlns/target">
<xs:complexType mixed="true">
<xs:attribute ref="gender"/>
</xs:complexType>
</xs:element>
I get this error message when I try to validate the schema:

Code: Select all

SystemID: /Users/souto/Scripts/treetagger/textosxml/hegischema.xsd
Location: 142:19
Description: sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',role'.
URL: http://www.w3.org/TR/xmlschema-1/#sch-props-correct
If I try this:

Code: Select all

	<xs:element name="role" xmlns:c="http://www.example.org/xmlns/cue" xmlns:t="http://www.example.com/xmlns/target">
<xs:complexType mixed="true">
<xs:attribute ref="gender"/>
</xs:complexType>
</xs:element>
I have a valid schema but I still get the same error message I posted yesterday:

Code: Select all

SystemID: /Users/souto/Scripts/treetagger/textosxml/borrar.xml
Location: 9:86
Description: cvc-complex-type.2.4.a: Invalid content was found starting with element 't:role'. One of '{generic, pron, name, role, demonym, title, entity, abbr}' is expected.
URL: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type
sorin wrote:The validation error means that in your XML Schema you did not define the role element to be in the "http://www.example.com/xmlns/target" namespace but you try to use it in the XML document with a prefix associated with this namespace.
Yes, that's more or less what I understood, but how do I define the role element to be in that namespace? That's what I don't know how to do and can't find.

Thanks again and sorry about the hassle.
xinelo

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Thu Feb 01, 2007 6:47 pm

Hello,

You want to define a role element in the "http://www.example.com/xmlns/target" namespace and a role element in the "http://www.example.com/xmlns/cue" namespace. For this you need two different XSD files because in one XSD file you can define only elements from one namespace. So you need to create one XSD file that defines all the types and elements of the "http://www.example.com/xmlns/target" namespace, other XSD file that defines all the types and elements of the "http://www.example.com/xmlns/cue" namespace and then create the XML file based on both XML Schema files that starts like the following:

Code: Select all

<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:t="http://www.example.com/xmlns/target"
xmlns:c="http://www.example.com/xmlns/cue"
xsi:schemaLocation="http://www.example.com/xmlns/target targetSchema.xsd
http://www.example.com/xmlns/cue cueSchema.xsd">

...
I suggest you read about the target namespace of a schema in an XML Schema tutorial before creating the two XSD files.


Regards,
Sorin

xinelo
Posts: 33
Joined: Wed Oct 04, 2006 6:25 pm

back to DTDs

Post by xinelo » Tue Feb 06, 2007 2:55 pm

True thanks, Sorin, for your help.

I've read the relevant parts of the document you sent, as well as other references, and I still don't get my Schema sheets to work. I don't know what to put in them. I don't know either if I must have two extra sheets (one for each prefix) and the original one (with the xs: namespace for all elements and attributes).

So I think I'll better off if I switch back to DTDs. If I have to have 2 schema sheets there's no such a great difference if I have to declare c:role and t:role as two elements in the DTD.

Thank you very much again for trying!

Cheers, Manuel

Post Reply