Jump to content

Dtd Entities As Macros


Guest asmodex

Recommended Posts

Guest asmodex

Hi!Sorry if I posted this in the wrong forum, but after several hours in W3C Schools and google this is my last hope.I have a large XML that is full of repeating nodes:

<parent id="1" value="Tom" option="x">	<child id="a" value="first" />	<child id="b" value="second" /></parent><parent id="2" value="######" option="x">	<child id="a" value="first" />	<child id="b" value="second" /></parent>

It would be nice if I could put the child nodes in an entity so that the result would be:

<parent id="1" value="Tom" option="x">&macro;</parent><parent id="2" value="######" option="x">&macro;</parent>

, or even part of the parent node as well:

<parent id="1" value="Tom" &macro;</parent><parent id="2" value="######" &macro;

I've seen examples for this inside DTD, but I need it inside an XML file. If I'm not mistaken parsed parameter entities sound like the right tool:

<!ENTITY macro "<child id="a" value="first" /><child id="b" value="second" />">

I hope that this is possible, and that I'm just too dumb to see how.

Link to comment
Share on other sites

Entities are only allowed within text nodes. I think they may contain raw XML contents (i.e. elements with attributes and everything), but this means only your first example may work.Entities are defined with DTD, and used in XML, so it's impossible not to use DTD. You can however embed DTD within an XML document. For example:

<?xml version="1.0"?><!DOCTYPE root [<!ENTITY macro "<child id="a" value="first" /><child id="b" value="second" />">]><root><parent id="1" value="Tom" option="x">&macro;</parent><parent id="2" value="######" option="x">&macro;</parent></root>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...