How to reference to a part of the XML doc?

P

panzy

Hi,

I have this structure:

<a>
<repeated_part>
<just_the_same_thing_and_more/>
</repeated_part>
</a>
<b>
<repeated_part>
<just_the_same_thing_and_more/>
</repeated_part>
</b>

Is it possible to refactor this at text doc level to something like this:

<repeated_part>
<just_the_same_thing_and_more/>
</repeated_part>
<a>
<reference to the repeated_part>
</a>
<b>
<reference to the repeated_part>
</b>

Pls note: I want parse this DOC and work with the DOM.
After parsing and using the DOM the tree should be very similar to the first
case:
The node <A> should have a child node <repeated part>

Is there any standard XML solution?

thx for answers
 
P

Patrick TJ McPhee

% I have this structure:
%
% <a>
% <repeated_part>
% <just_the_same_thing_and_more/>
% </repeated_part>
% </a>
% <b>
% <repeated_part>
% <just_the_same_thing_and_more/>
% </repeated_part>
% </b>
%
% Is it possible to refactor this at text doc level to something like this:
%
% <repeated_part>
% <just_the_same_thing_and_more/>
% </repeated_part>
% <a>
% <reference to the repeated_part>
% </a>
% <b>
% <reference to the repeated_part>
% </b>

Note that neither of these is well-formed. Anyway, doing it like this will
result in a different DOM tree. You can put the repeated part in an entity
definition, though, something like:

<!DOCTYPE missing-outer-element [
<!ENTITY repeated_part '<just_the_same_thing_and_more/>'>
]>

<missing-outer-element>
<a>
&repeated_part;
</a>
<b>
&repeated_part;
</b>
</missing-outer-element>

This will result in identical DOM trees provided you make the spacing
consistent.
 
P

panzy

Hi Patrick,

Thx for your fast answer.

I'd like to use elements, attributes as the repeated part. With other words
my repeated part is a chunk of XML text.
Can I do this with Entities what you recommend?

I'd like to avoid DTD. I use an external xsd schema. Is any other way to
complete my task?

thx for answers
..
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top