Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
This interface defines methods
that receive notification of specific events within a DTD, such as element and
attribute declaration. This is another item only good for very specific cases,
again, XML editors and components that must know the exact lexical structure of
documents and their DTDs come to mind. This interface defines callbacks that
gives specific information about DTD declarations. Element and attribute definitions
invoke the appropriate callback with their name (and the element names for
attributes) as well as constraint information. While this is a fairly rigid set
of data for attributes, elements only receive a string with the constraint
model as pure text. Additionally, internal and external entity reference
notifications are defined.
Method Overviews
The implementation of methods in this class depends upon your
application. However I have given examples of method which I have used in my
application so thought might be interested too.
Example of attributeDecl()
/**
* This
method reports an attribute type declaration i.e. <!ATTLIST> in DTD.
* @param
eName The name of the associated element.
* @param
aName The name of the attribute.
* @param
type A string representing the attribute type.
* @param
valueDefault A string representing the attribute default ("#IMPLIED",
"#REQUIRED", or "#FIXED") or null if none of these applies.
* @param
value A string representing the attribute's default value, or null if there is
none.
* This
method reports an element type declaration(<!ELEMENT) in DTD.
* @param
name The element type name.
* @param
model The content model as a normalized string.
*/
public void
elementDecl(String name, String
model)
{
System.out.println("Start of elementDecl");
System.out.println("name :"+name);
System.out.println("model :"+model);
System.out.println("End of elementDecl");
}
Example of How to use DeclHandler:
DeclHandlerImpl declhandlerImpl = new
DeclHandlerImpl();
parser.setProperty("http://xml.org/sax/properties/declaration-handler",declhandlerImpl);
//If the reader does not support declaration events, it will throw a SAXNotRecognizedException or a SAXNotSupportedException when you attempt
to register the handler.
/**
*Before
using this ensure that your xml file contains DOCTYPE declaration with a DTD.
**/
<!DOCTYPE
purchaseOrder SYSTEM "E:\topxml\purchaseorder.dtd">