Hi:
DTD is Document Type Definition. It defines the grammar to
which the XML document is expected to adhere to.
Consequently, the parser (Xerces in this case) uses the DTD
to validate the validity of the XML document.
This can be acheived through
// Instantiate the parser and set the properties
DOMParser parser = new DOMParser();
// This sets on the DTD validation
parser.setFeature( "http://xml.org/sax/features/validation", true);
// Parse the file
parser.parse( "file:///Drive:/pathFrag01/pathFrag02/fileName.xml" );
If you would like to access the information like children of
particular element, parent of a particular element etc.
Then
1. You would need to read up the DOM API Standard.
2. Learn basic of tree data structure.
Once you have done that work, you will find yourself better equipped
to succeed in your endeavours. In short, there is no short cut to spending
sometime to learn some concepts, rather than just begging for some code
on the mailing list!
Then you will be able to appreciate code, such as the one below
// Get the parent node
org.w3c.dom.Document doc = parser.getDocument();
System.out.println( "doc NodeName : " + doc.getNodeName() );
Another fragment is
// Traverse DOM Tree
if( true == doc.hasChildNodes() )
{
// Use the getDocumentElement() method
Node rootNode = doc.getDocumentElement();
System.out.println( "Root NodeName : " + rootNode.getNodeName() );
if( true == rootNode.hasChildNodes() )
{
int nOfChildren = rootNode.getChildNodes().getLength();
System.out.println( "Root node has " + nOfChildren + " children" );
dumpChildNodes( rootNode );
//Node node = rootNode.get
}
else
{
System.out.println( "Root Node doesnot have child nodes" );
}
}
/**
* Dump Child Nodes
*/
public static void dumpChildNodes( org.w3c.dom.Node node )
{
for( Node childNode = node.getFirstChild(); childNode != null; childNode = node.getNextSibling() )
{
System.out.print( "* : " );
System.out.println( "ChildNodeName : " + childNode.getNodeName() );
}
}
Your mail seems to suggest "couldn't care less kind of attitude" while
your punchline seems to say otherwise.
-Saifi Khan.
-----Original Message-----
From: DK [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 09, 2001 11:16 AM
To: [EMAIL PROTECTED]
Subject: API to parse dtd
Hi,
I need to get information from dtd like children of a particular
element,parent of a particular element etc.
Is it possible using any API of xerces parser?
TIA,
DK
Never forget your past ,for you should
Never repeat your mistakes .
----------------------------------------
http://mail.indiainfo.com
First you had 10MB of free mail space.
Now you can send mails in your own language !!!
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
