Representing duplicated data in XML

C

Charles Packer

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.
 
T

Troy Cauble

In comp.text.xml Charles Packer said:
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
 
J

Jürgen Exner

Charles Packer said:
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
 
C

Charles Packer

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.
 
P

Peter Flynn

Troy said:
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
 
P

Peter Flynn

Troy said:
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
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top