Representing duplicated data in XML

Discussion in 'XML' started by Charles Packer, Aug 28, 2008.

  1. Does XML have a way to refer to duplicated data?

    Suppose I create a source text that consists of rules for
    generating an object text of expanded material when parsed by
    a program that knows the rules. Suppose that
    one of the rules is long and occurs multiple times in
    the source text. I want to have only one instance of this
    rule in the source text for compactness and ease of editing
    it later. In this example...

    ..
    ..
    ..
    <situation> something </situation>
    <action1> action specific to something </action1>
    <action2>
    .
    . ...often done in any situation...
    .
    </action2>
    <situation) something else </situation>
    <action1> action specific to something else</action1>
    ???
    ..
    ..
    ..

    ....the question marks are where I want to insert
    correct XML that compactly signals a second use of
    datum "action2". I learned from an XML tutorial that I can
    assign an _attribute_ to action2. Might a solution to
    the problem involve an attribute? The tutorials I perused
    didn't have anything about this use of attributes.

    --
    Charles Packer
    http://cpacker.org/whatnews
    mailboxATcpacker.org
    Charles Packer, Aug 28, 2008
    #1
    1. Advertising

  2. Charles Packer

    Troy Cauble Guest

    In comp.text.xml Charles Packer <> wrote:
    > Does XML have a way to refer to duplicated data?


    > .
    > .
    > <situation> something </situation>
    > <action1> action specific to something </action1>
    > <action2>
    > .
    > . ...often done in any situation...
    > .
    > </action2>
    > <situation) something else </situation>
    > <action1> action specific to something else</action1>
    > ???
    > .
    > .
    > .
    >
    > ...the question marks are where I want to insert
    > correct XML that compactly signals a second use of
    > datum "action2". I learned from an XML tutorial that I can
    > assign an _attribute_ to action2. Might a solution to
    > the problem involve an attribute? The tutorials I perused
    > didn't have anything about this use of attributes.



    You could have optional id and ref elements.

    <action id='myUniqueId'>blah....</action>
    ...
    <action ref='myUniqueId'/>

    with documentation saying to use a ref attribute *OR* content.
    Better than documentation is something you can validate
    with DTD/XML Schema/whatever. Such as

    <actionref ref='myUniqueId'/>

    Where actionref requires ref, does not allow content, and can be
    used wherever action can.

    Depending on your app, you might consider it poor form to
    reference an action in a situation from another situation.
    So you might want a section of

    <actiondefs>
    <actiondef id='myUniqueId'>blah...</actiondef>
    </actiondefs>

    where id is required (and no longer allowed in action).

    Also, you probably don't want to number your action element
    names "action1", "action2", etc. Just use "action". Order
    is significant within sub-elements.

    -troy
    Troy Cauble, Aug 28, 2008
    #2
    1. Advertising

  3. Charles Packer <> wrote:
    >Does XML have a way to refer to duplicated data?
    >
    >Suppose I create a source text that consists of rules for
    >generating an object text of expanded material when parsed by
    >a program that knows the rules. Suppose that
    >one of the rules is long and occurs multiple times in
    >the source text. I want to have only one instance of this
    >rule in the source text for compactness and ease of editing
    >it later. In this example...


    Why not define all your rules in one section and assign a unique ID to
    each? And later simply reference that ID at the location of the
    application instead of textually copying the rule. That's how it is
    usually done.
    However, what on earth does this have to do with Perl modules?

    jue
    Jürgen Exner, Aug 29, 2008
    #3
  4. On Aug 28, 5:04 pm, Troy Cauble <> wrote:
    > You could have optional id and ref elements.
    >
    > <action id='myUniqueId'>blah....</action>
    > ...
    > <action ref='myUniqueId'/>
    >
    > with documentation saying to use a ref attribute *OR* content.
    > Better than documentation is something you can validate
    > with DTD/XML Schema/whatever. Such as



    Thanks very much for your help. Is this what you had in mind?


    <actiondefs>
    <action id='oftendone'>
    .
    . ...often done in any situation...
    .
    </action>
    ..
    ..
    ..
    </actiondefs>
    ..
    ..
    ..
    <situation> something </situation>
    <action> action specific to something </action>
    <action ref='oftendone'/>
    <situation> something else </situation>
    <action> action specific to something else</action>
    <action> ref='oftendone'/>
    ..
    ..
    ..
    I guess this is the "weak" implementation of your suggestion.
    The "strong" version, with validation by schemas and such, I
    don't think I need for the task in question. A colleague was
    editing huge amounts of SQL, much of which is boilerplate, and
    asked me to devise a way to generate the SQL instead from some
    kind of dialogue. What I'm going to propose instead is that she
    still edit a file, but in place of the SQL itself, it will be
    a template for recording only the salient information. I'll
    write a Perl script to parse it and generate the SQL. In pondering
    how to deal with the duplicated data, I started thinking of how
    to represent it by reference...and realized that I was about to
    reinvent XML -- so why not use the real thing? Still, by keeping
    the XML constructs to a minimum, I shouldn't need an XML parser.

    My apologies for crossposting to comp.lang.perl.modules,
    incidentally. I checked first and found other queries about XML
    therein, and the XML newsgroup has such low traffic I was
    afraid I'd be waiting too long for a response.

    --
    Charles Packer
    http://cpacker.org/whatnews
    mailboxATcpacker.org
    Charles Packer, Aug 29, 2008
    #4
  5. Charles Packer

    Peter Flynn Guest

    Troy Cauble wrote:
    > In comp.text.xml Charles Packer <> wrote:
    >> Does XML have a way to refer to duplicated data?

    >
    >> .
    >> .
    >> <situation> something </situation>
    >> <action1> action specific to something </action1>
    >> <action2>
    >> .
    >> . ...often done in any situation...
    >> .
    >> </action2>
    >> <situation) something else </situation>
    >> <action1> action specific to something else</action1>
    >> ???
    >> .
    >> .
    >> .
    >>
    >> ...the question marks are where I want to insert
    >> correct XML that compactly signals a second use of
    >> datum "action2". I learned from an XML tutorial that I can
    >> assign an _attribute_ to action2. Might a solution to
    >> the problem involve an attribute? The tutorials I perused
    >> didn't have anything about this use of attributes.

    >
    >
    > You could have optional id and ref elements.
    >
    > <action id='myUniqueId'>blah....</action>
    > ...
    > <action ref='myUniqueId'/>
    >
    > with documentation saying to use a ref attribute *OR* content.
    > Better than documentation is something you can validate
    > with DTD/XML Schema/whatever. Such as
    >
    > <actionref ref='myUniqueId'/>
    >
    > Where actionref requires ref, does not allow content, and can be
    > used wherever action can.
    >
    > Depending on your app, you might consider it poor form to
    > reference an action in a situation from another situation.
    > So you might want a section of
    >
    > <actiondefs>
    > <actiondef id='myUniqueId'>blah...</actiondef>
    > </actiondefs>
    >
    > where id is required (and no longer allowed in action).
    >
    > Also, you probably don't want to number your action element
    > names "action1", "action2", etc. Just use "action". Order
    > is significant within sub-elements.


    Sadly, SGML's CONREF (Content Reference) attribute type, which was
    (among other things) for this exact type of situation, never made it
    into XML.

    ///Peter
    Peter Flynn, Sep 6, 2008
    #5
  6. Charles Packer

    Peter Flynn Guest

    Troy Cauble wrote:
    > In comp.text.xml Charles Packer <> wrote:
    >> Does XML have a way to refer to duplicated data?

    >
    >> .
    >> .
    >> <situation> something </situation>
    >> <action1> action specific to something </action1>
    >> <action2>
    >> .
    >> . ...often done in any situation...
    >> .
    >> </action2>
    >> <situation) something else </situation>
    >> <action1> action specific to something else</action1>
    >> ???
    >> .
    >> .
    >> .
    >>
    >> ...the question marks are where I want to insert
    >> correct XML that compactly signals a second use of
    >> datum "action2". I learned from an XML tutorial that I can
    >> assign an _attribute_ to action2. Might a solution to
    >> the problem involve an attribute? The tutorials I perused
    >> didn't have anything about this use of attributes.

    >
    >
    > You could have optional id and ref elements.
    >
    > <action id='myUniqueId'>blah....</action>
    > ...
    > <action ref='myUniqueId'/>
    >
    > with documentation saying to use a ref attribute *OR* content.
    > Better than documentation is something you can validate
    > with DTD/XML Schema/whatever. Such as
    >
    > <actionref ref='myUniqueId'/>
    >
    > Where actionref requires ref, does not allow content, and can be
    > used wherever action can.
    >
    > Depending on your app, you might consider it poor form to
    > reference an action in a situation from another situation.
    > So you might want a section of
    >
    > <actiondefs>
    > <actiondef id='myUniqueId'>blah...</actiondef>
    > </actiondefs>
    >
    > where id is required (and no longer allowed in action).
    >
    > Also, you probably don't want to number your action element
    > names "action1", "action2", etc. Just use "action". Order
    > is significant within sub-elements.


    Sadly, SGML's CONREF (Content Reference) attribute type, which was
    (among other things) for this exact type of situation, never made it
    into XML.

    ///Peter
    Peter Flynn, Sep 6, 2008
    #6
    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. Simon Brooke
    Replies:
    0
    Views:
    438
    Simon Brooke
    Oct 12, 2003
  2. James
    Replies:
    1
    Views:
    2,183
    Richard Tobin
    Apr 25, 2004
  3. Hans Oesterholt-Dijkema

    Representing Meta Data using an XML Schema

    Hans Oesterholt-Dijkema, Apr 13, 2005, in forum: XML
    Replies:
    0
    Views:
    343
    Hans Oesterholt-Dijkema
    Apr 13, 2005
  4. Venky
    Replies:
    0
    Views:
    531
    Venky
    Jun 27, 2005
  5. Replies:
    7
    Views:
    416
    Peter Flynn
    Jun 12, 2008
Loading...

Share This Page