picking value of one attribute based on a child elements attribute? XPath?

V

vjethava

Hi,

I'm relatively new to xml. I want to have a xml element of the form:

<!ELEMENT CAR (MAKE, COMPANY)>
<!ATTLIST CAR
TYPE PCDATA
PRICE PCADATA>

<!ELEMENT COMPANY (HQ, COMPANY_TYPE)>

Is there a way such that CAR/TYPE has the same value as
CAR/COMPANY/COMPANY_TYPE either using DTD or a schema . For example,
whenever,

CAR/COMPANY/COMPANY_TYPE = "PRICEY"
then,
CAR/TYPE = "PRICEY"

I think something like XPath is needed but am not sure how to go about
getting this. Can I use XPath inside XML elements to point to value of
other elements.

Vinay
 
P

Peter Flynn

Hi,

I'm relatively new to xml. I want to have a xml element of the form:

<!ELEMENT CAR (MAKE, COMPANY)>
<!ATTLIST CAR
TYPE PCDATA
PRICE PCADATA>

PCDATA is for element character data content. For attributes just use
CDATA. You also need to specify if a value is compulsory (#REQUIRED)
or optional (#IMPLIED), eg

<!ELEMENT COMPANY (HQ, COMPANY_TYPE)>

Is there a way such that CAR/TYPE has the same value as
CAR/COMPANY/COMPANY_TYPE either using DTD or a schema. For example,
whenever,

CAR/COMPANY/COMPANY_TYPE = "PRICEY"
then,
CAR/TYPE = "PRICEY"

Not in an XML DTD. Something similar is possible in SGML (CONREF).
But why do you want to do this? It's only necessary to give information
once.
I think something like XPath is needed but am not sure how to go about
getting this. Can I use XPath inside XML elements to point to value of
other elements.

No. That's something you do in your processing language (eg XSLT). But
using a Schema language may help.

///Peter
 
H

Henry S. Thompson

W3C XML Schema identity constraints can enforce the kind of equality
you require -- see the W3C XML Schema Primer [1] for an introduction.

ht

[1] http://www.w3.org/TR/xmlschema-0/
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top