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

Discussion in 'XML' started by vjethava@gmail.com, Mar 1, 2006.

  1. Guest

    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
    , Mar 1, 2006
    #1
    1. Advertising

  2. Peter Flynn Guest

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

    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/
    Peter Flynn, Mar 1, 2006
    #2
    1. Advertising

  3. 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]
    Henry S. Thompson, Mar 6, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alastair Cameron
    Replies:
    1
    Views:
    7,403
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Replies:
    0
    Views:
    426
  3. leon
    Replies:
    0
    Views:
    427
  4. Jeff Rodriguez
    Replies:
    23
    Views:
    1,116
    David Schwartz
    Dec 9, 2003
  5. Rita
    Replies:
    14
    Views:
    164
    Jahagirdar Vijayvithal S
    Dec 5, 2005
Loading...

Share This Page