my dog learned polymorphism
The moose likes XML and Related Technologies and the fly likes How to restrict Element content ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to restrict Element content ??" Watch "How to restrict Element content ??" New topic

How to restrict Element content ??

Mohan xml

Joined: Apr 06, 2001
Posts: 3
Dear all friends,
I would like to know can we, restrict content(i mean length,values etc....) of an XML element using XML DTD's. Also how to restrict the length of an ATTRIBUTE.
for EX:
<?xml version="1.0" encoding="UTF-8"?>
<TYPE desc='xml'>FORUM</TYPE>
I want a DTD to validate the above xml as
1) element JAVARANCH should contain only XML as value.
2) the attribut desc , should contain value with only 3 chars maximum.
Thanx in advance
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13025
If I understand your question correctly, you can't use a DTD for this. Various projects are experimenting with "XML Schema" - a sort of DTD replacement that can impose restrictions on XML content. is a good place to start.
author of:
Mohan xml

Joined: Apr 06, 2001
Posts: 3
Dear Bill,
But can i restrict , the length of the attribute in the tag using DTD, if so how ??
Thanx in advance..
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
I know you can specify a value for an elemen and make it "final" by desginating the value "fixed". I don't know if you can restrict the length of an attribute value. Bill's link was comprehensive and in depth. Excellent site! Thanks Bill.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Please read the JavaRanch Name Policy and re-register using a name that complies with the rules.
Thanks for your cooperation.
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link:
subject: How to restrict Element content ??
It's not a secret anymore!