Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Representing duplicated data in XML

Reply
Thread Tools

Representing duplicated data in XML

 
 
Charles Packer
Guest
Posts: n/a
 
      08-28-2008
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
 
Reply With Quote
 
 
 
 
Troy Cauble
Guest
Posts: n/a
 
      08-28-2008
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      08-29-2008
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
 
Reply With Quote
 
Charles Packer
Guest
Posts: n/a
 
      08-29-2008
On Aug 28, 5:04 pm, Troy Cauble <t...@alcatel-lucent.com> 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
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      09-06-2008
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
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      09-06-2008
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
 
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
representing a directory structure in XML James Owens XML 8 11-24-2005 09:23 PM
Representing BNF grammer using XML Venky XML 0 06-27-2005 05:15 PM
Representing Meta Data using an XML Schema Hans Oesterholt-Dijkema XML 0 04-13-2005 08:29 PM
Representing Null vs. EmptyString in XML James XML 1 04-25-2004 03:17 PM
XML DTD or schema for representing entities and relationships (SQL)? Simon Brooke XML 0 10-12-2003 02:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57