Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > picking value of one attribute based on a child elements attribute? XPath?

Reply
Thread Tools

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

 
 
vjethava@gmail.com
Guest
Posts: n/a
 
      03-01-2006
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

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      03-01-2006
wrote:
> 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

<!ATTLIST CAR TYPE CDATA #REQUIRED PRICE CDATA #IMPLIED>

> <!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
--
XML FAQ: http://xml.silmaril.ie/
 
Reply With Quote
 
 
 
 
Henry S. Thompson
Guest
Posts: n/a
 
      03-06-2006
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:
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the value of an attribute according to the value of another attribute patrizio.trinchini@googlemail.com XML 8 08-22-2006 02:53 PM
wrapping long attribute value (line-continuation for attribute value) lophiomys@gmx.at XML 1 08-02-2006 01:18 PM
restrict the value of one child based on value from another child leon XML 0 09-27-2005 03:32 PM
schema for different complex elements based on attribute value user@domain.invalid XML 0 07-20-2004 03:29 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments