using parameter entities in xml

hi professional
just wondering if someone can help me in how to use parameter entities in dtd to represent text that i need to repeat many times in xml within the DTD file

i uploaded exmaple.xml to see the code which has both xml,dtd code
kindly i would be thankful if someone can answer my inquiry
example.xml
Hatim1985Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
Here is what you can do

<!ENTITY % ccard "credit-card">
<!ELEMENT %ccard; (nickname,card-type,cardholder,credit-card-number,credit-card-expiration,billing-address)>
<!ELEMENT credit-card-info (%ccard;)+ >

But I have a feeling you want this
<!ELEMENT %ccard;-number (#PCDATA)>

That is simply not allowed


0
TommySzalapskiCommented:
There is no reason not to just keep the DTD the way it is in your file. It's easy to read and understand and does not violate any rules. It's good to be verbose in code.

If you are just trying to save typing time, then use variables like %c for "credit-card-" and %p for "payment-" and then use the 'Find and Replace' feature at the end (using Word or Wordpad or most text editors). Then you can just type the short %c but the final result will have the correct "credit-card-".
0
Gertone (Geert Bormans)Information ArchitectCommented:
well, parameter entities are very good for many reasons
- specialising the DTD throught the Internal Subset of the DTD
- introduce multilinguality in the Model element names (some sort of application of the above)
- reuse of blocks of content models through a complex DTD
- allowing future maintenance
- referencing other DTD parts in different files
- ...
All the serious DTDs I have worked with have a multitude of parameter entities doing one of the above, including my own DTDs

If Tommy means with his comments that parameter entities have no use, I strongly diagree
If he means that there is no reason for using in your DTD as it currently stands, I tend to agree.
You can definitely not use parameter entities the way I think you want them

Please don't start changing DTDs automatically with find/replace sort of stuff.
It makes usage of your DTD in XML workflows more error prone

Just a quick comment
In your DTD you have
street, payment-street, shipping-street
This is pretty uncommon modelling in XML, since in XML hierarchical context is important, so there is no extra information given by doing it that way
I strongly recommend your model to have only street
It will make your DTD easier to document, easier to maintain and easier to learn for users.
From the processing point of view, an XPath shipping-address/street is as easy as shipping-address/shipping-street

And then... you should use parameter entities of course.
I strongly recommend the DTD to be changed like this


<!ELEMENT customers (customer*)>
<!ELEMENT customer (credit-card-info,order-history-info)>
<!ELEMENT credit-card-info (credit-card+)>
<!ELEMENT credit-card (nickname,card-type,cardholder,credit-card-number,credit-card-expiration,billing-address)>
<!ELEMENT nickname (#PCDATA)>
<!ELEMENT card-type (#PCDATA)>
<!ATTLIST card-type type (mastercard|visa|american-express) "mastercard">
<!ELEMENT cardholder (#PCDATA)>
<!ELEMENT credit-card-number (#PCDATA)>
<!ELEMENT credit-card-expiration (#PCDATA)>

<!ENTITY % address "(street,city,state,four-digit)" >
<!ENTITY % name-addr "(name, %address;)" >
<!ELEMENT billing-address %name-addr;>
<!ELEMENT name (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT four-digit (#PCDATA)>

<!ELEMENT order-history-info (order+)>
<!ELEMENT order (payment-info,shipping-address)>
<!ELEMENT payment-info %name-addr;>
<!ELEMENT payment-type (#PCDATA)>
<!ATTLIST payment-type type (mastercard|visa|american-express) "mastercard">
<!ELEMENT payment-credit-number (#PCDATA)>
<!ELEMENT expiration-date (#PCDATA)>
<!ELEMENT payment-billing-address %name-addr;>
<!ELEMENT shipping-address %address;

Open in new window

0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Gertone (Geert Bormans)Information ArchitectCommented:
seem to have overwritten one line too much
<!ELEMENT payment-info (payment-type,payment-credit-number,expiration-date,payment-billing-address)>

here is you new XML

<!DOCTYPE customers SYSTEM "example.dtd">
<customers>
 <customer>
  <credit-card-info>
  <credit-card>
  <nickname>ccc</nickname>
    <card-type>mastercard</card-type>
    <cardholder>aaa</cardholder>
    <credit-card-number>0101</credit-card-number>
    <credit-card-expiration>13-12-2012</credit-card-expiration>
    <billing-address>
      <name>aaa</name>
      <street>aaa</street>
      <city>aaa</city>
      <state>aaa</state>
      <four-digit>0000</four-digit>
    </billing-address>
   </credit-card>
  </credit-card-info> 
  <order-history-info>
  <order>
    <payment-info>
     <payment-type>mastercard</payment-type>
      <payment-credit-number>0101</payment-credit-number>
      <expiration-date>13-12-2012</expiration-date>
	  <payment-billing-address>
       <name>aaa</name>
       <street>aaa</street>
       <city>aaa</city>
       <state>aaa</state>
       <four-digit>000</four-digit>
      </payment-billing-address>
    </payment-info>	
    <shipping-address>
      <street>aaa</street>
       <city>aaa</city>
       <state>aaa</state>
       <four-digit>0000</four-digit>
    </shipping-address>
	</order>
  </order-history-info>
  </customer>
</customers>

Open in new window

0
TommySzalapskiCommented:
Please don't start changing DTDs automatically with find/replace sort of stuff.
It makes usage of your DTD in XML workflows more error prone


If you are doing this in a work environment, then I agree with everything Gertone said. If this is for a class assignment, then I'd go with the quick and simple solution.
0
Hatim1985Author Commented:
Gertone: thank u for reposed but i found what u trying to explain is not clear

have a look please again to this
            <credit-card-info>
                  <credit-card>
                        <nickname>ccc</nickname>
                        <card-type>mastercard</card-type>
                        <cardholder>aaa</cardholder>
                        <credit-card-number>0101</credit-card-number>
                        <credit-card-expiration>13-12-2012</credit-card-expiration>
                        <billing-address>
                              <name>aaa</name>
                              <street>aaa</street>
                              <city>aaa</city>
                              <state>aaa</state>
                              <four-digit>0000</four-digit>
                        </billing-address>
                  </credit-card>
            </credit-card-info>

<!ELEMENT credit-card-info (credit-card+)>
<!ENTITY % creditcard "(card-type,credit-card-number,credit-card-expiration,billing-address)">
<!ELEMENT credit-card (nickname, cardholder, %creditcard;)>
<!ELEMENT card-type (#PCDATA)>
<!ATTLIST card-type type (mastercard|visa|american-express) "mastercard">
<!ELEMENT credit-card-number (#PCDATA)>
<!ELEMENT credit-card-expiration (#PCDATA)>
<!ENTITY % address "name,street,city,state,four-digit">
<!ELEMENT billing-address (%address;)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT four-digit (#PCDATA)>
<!ELEMENT nickname (#PCDATA)>
<!ELEMENT cardholder (#PCDATA)>

is that right ?? cos it show me error in xml  that say element card-type is not valid for content model (nickname,cardholder,card-type,credit-card-number,credit-card-expiration,billing-address)
could u please explain why they saying this, and how to solve it

Tommy: neither work environment nor class assignment, this is personal learning for xml
0
Gertone (Geert Bormans)Information ArchitectCommented:
If this is a learning process, you need to know that various (sometimes conflicting) requiremenst for a DTD model are important to look at
- users need to easily understand and learn how to use the DTD
- the DTD should have a form that makes it easy to do maintenance and changes
- it should be easy to create a valid XML
- the valid XML should be easy to process using XML tools

usually it helps
- having as few different elements as possible,
- have names that clearly indicate what is to be expected in the fields
- have containers for grouped stuff
- use the hierarchy wisely

but good modelling is an art on its own, you will learn over time


For your little problem, you need to swap two elements in place

<credit-card-info>
    <credit-card>
        <nickname>ccc</nickname>
        <cardholder>aaa</cardholder>
        <card-type>mastercard</card-type>
        <credit-card-number>0101</credit-card-number>
        <credit-card-expiration>13-12-2012</credit-card-expiration>
        <billing-address>
            <name>aaa</name>
            <street>aaa</street>
            <city>aaa</city>
            <state>aaa</state>
            <four-digit>0000</four-digit>
        </billing-address>
    </credit-card>
</credit-card-info>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TommySzalapskiCommented:
Tommy: neither work environment nor class assignment, this is personal learning for xml
My mistake. Don't do any quick and dirty fixes then.
0
Hatim1985Author Commented:
it was partially answers  from Gertone
0
Gertone (Geert Bormans)Information ArchitectCommented:
partially???
well, well, well, I think you got  a whole lot more than what you asked for.
What you wanted to do at start is not possible, but "not possible" is as good an answer as well
Remember for future questions... experts here like to help, but the appreciation should be correct... we don't necessarily want points but we hate B-grades
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Theory

From novice to tech pro — start learning today.