• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

very basic question --- validating with DTD

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im very new to XML...and asking a avery basic question
I have made an XML file
public class TestXML {
/**
* TestXML constructor comment.
*/
public TestXML() {
super();
}
public static void main(String args [])
{

try {
Vector name= new Vector();
Vector age= new Vector();
Vector state= new Vector();
name.addElement("name1");
name.addElement("name2");

age.addElement("age1");
age.addElement("age2");
state.addElement("state1");
state.addElement("state2");
String xmlFile = "C:/XML/test.xml";
FileWriter XMLFileFileWriter = new FileWriter("C:/XML/test.xml");
String prolog = "<?xml version='1.0' encoding='utf-8'?>\n";
XMLFileFileWriter.write(prolog);

String dtdInfo = "<!DOCTYPE userprofile SYSTEM \"http://localhost/estart/profile.dtd\">\n";
XMLFileFileWriter.write(dtdInfo);

XMLFileFileWriter.write("<userprofile>\n");
for(int i=0; i<name.size();i++){
XMLFileFileWriter.write("<name>"+name.elementAt(i)+"</name>\n");
XMLFileFileWriter.write("<age>"+age.elementAt(i)+"</age>\n");
XMLFileFileWriter.write("<state>"+state.elementAt(i)+"</state>\n");
}
XMLFileFileWriter.write("</userprofile>\n");

XMLFileFileWriter.close();
}
catch (Exception e) {
}


}
}

AND the DTD is as follows :
<!ELEMENT profile (userprofile)>
<!ELEMENT userprofile (name,age, state)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT age (#PCDATA)>
<!ELEMENT state (#PCDATA)>
I have Xalan Xerces.
Now what should i do to confirm that my XMl file confirms to my dtd.
Please help
Thanx
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this tutorial it will help you.
Validating XML against it DTD, link=validating XML
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you should use DOM or JDom to write an XML decument in memory, then output to a file. In this way, you can at least to guarantee the well-formness of your file. You can also to turn the validation on.
Write line-by-line, any smart text editor can do better job than you write Java code to do it.
 
mou haj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx balaj
the tutorial is great .. now im trying with schemas...
can you tell me where im going wrong...i have placed another question
 
mou haj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi balaji
Im very new to XML...
Can you tell me suppose I have an XML file and I have the XML schema .. how now ill have to extract the data and fill in a database. I mean I know ill have to parsing... but how.. can u gimme some sample code...or refer any good tutorial ...
thanx
Moumita
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mou haj:
Hi balaji
Im very new to XML...
Can you tell me suppose I have an XML file and I have the XML schema .. how now ill have to extract the data and fill in a database. I mean I know ill have to parsing... but how.. can u gimme some sample code...or refer any good tutorial ...
thanx
Moumita


here u go!..


Using JDBC to extract data into XML , Using JDBC to insert data from XML into a database and also this xml Schema validation using XERCES2
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic