I am having trouble trying to implement parameter entities so that i can repeat text multiple times within the DTD.

example XML code:

<accounts>
<luke>
<shipping_address>
<address></address>
<street></street>
<city></city>
<postcode></postcode>
</shipping_address>
</luke>

<angie>
<billing_address>
<address></address>
<street></street>
<city></city>
<postcode></postcode>
</billing_address>
</angie>
</accounts>

The address, street, city, postcode elements both have the same information. How would i reuse these sets of elements multiple times within a DTD document using parameter entity ? i know the key syntax is the % sign, but i can't seem to understand how to code it properly.

Hello
entity parameter can be used only in external dtd file
I would also change the structure of the XML

bad example not working

<?xml version="1.0"?>
<!DOCTYPE accounts [
<!ENTITY % select "address ,street ,city ,postcode" >
<!ELEMENT accounts (item)+>
<!ELEMENT item (name,shipping_address?,billing_address?)>
<!ELEMENT name (lastname,firsname)>
<!--
<!ELEMENT shipping_address (address,street,city,postcode)>
-->
<!ELEMENT shipping_address ((% select;))>
<!ELEMENT billing_address (address,street,city,postcode)>
<!ELEMENT lastname  (#PCDATA)> 
<!ELEMENT firsname  (#PCDATA)> 
<!ELEMENT address   (#PCDATA)> 
<!ELEMENT street    (#PCDATA)> 
<!ELEMENT city      (#PCDATA)>
<!ELEMENT postcode  (#PCDATA)>  

]>
<accounts>
	<item>
		<name>
			<lastname></lastname>
			<firsname></firsname>
		</name>
		<shipping_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</shipping_address>
		<billing_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</billing_address>
	</item>
	<item>
		<name>
			<lastname></lastname>
			<firsname></firsname>
		</name>
		<shipping_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</shipping_address>
		<billing_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</billing_address>
	</item>
	<item>
		<name>
			<lastname></lastname>
			<firsname></firsname>
		</name>
		<shipping_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</shipping_address>
	</item>
</accounts>

with extern will be work

DTD

<!ENTITY % select "address ,street ,city ,postcode" >
<!ELEMENT accounts         (item)+>
<!ELEMENT item             (name,shipping_address?,billing_address?)>
<!ELEMENT name             (lastname,firsname)>
<!--
<!ELEMENT shipping_address (address,street,city,postcode)>
<!ELEMENT billing_address  (address,street,city,postcode)>
-->
<!ELEMENT shipping_address (%select;)>
<!ELEMENT billing_address  (%select;)>
<!ELEMENT lastname         (#PCDATA)> 
<!ELEMENT firsname         (#PCDATA)> 
<!ELEMENT address          (#PCDATA)> 
<!ELEMENT street           (#PCDATA)> 
<!ELEMENT city             (#PCDATA)>
<!ELEMENT postcode         (#PCDATA)>

include xml

<?xml version="1.0"?>
<!DOCTYPE accounts SYSTEM "accounts.dtd">
<accounts>
	<item>
		<name>
			<lastname></lastname>
			<firsname></firsname>
		</name>
		<shipping_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</shipping_address>
		<billing_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</billing_address>
	</item>
	<item>
		<name>
			<lastname></lastname>
			<firsname></firsname>
		</name>
		<shipping_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</shipping_address>
		<billing_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</billing_address>
	</item>
	<item>
		<name>
			<lastname></lastname>
			<firsname></firsname>
		</name>
		<shipping_address>
			<address></address>
			<street></street>
			<city></city>
			<postcode></postcode>
		</shipping_address>
	</item>
</accounts>

why it works with external DTD
when loading the external DTD is parsed, the entity and then used
this does not happen when the XML file with DTD interen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.