XML prog

Embed Size (px)

Citation preview

  • 7/28/2019 XML prog

    1/11

    1. Program for XML css named as XML_css_Demo.xml

    XML BibleWinstonWiely Fourth

    0-2345-2345-9Rs. 400

    Java Complete ReferenceHerbert ShieldTMH Fourth0-2345-2345-11Rs. 480

    Introduction to Web technologyAkhilesh Kumar SinghTech MaxThird0-2345-2345-13Rs. 350

    Introduction to CReema TharejaOrfordSecond

    0-2345-2345-14Rs. 300

    2. Program from CSS file named as library.css

    Catalog{

    font-family:arial;color:red;font-size:16pt;

    }Book{

    font-family:New Times Roman;color:blue;font-size:14pt;

    }Title{

    font-family:arial;color:green;font-size:12pt;

  • 7/28/2019 XML prog

    2/11

    }Author{

    font-family:arial;color:magenta;

    }Publication, Edition, ISBN, Price{

    display:block;

    font-family:arial;color:black;font-size:10pt;margin-left:20pt;

    }

    3. Program of Internal DTD named as DTD_internal.xml

    ]>

    SunilGaziabadFirst80 Percent

    4. Program of External DTD named as DTD_external.xml and DTD_external.dtd

    AjayGaziabadFirst80 Percent

    DTD_external.dtd

    5. Program of External DTD with XML and CSS named asDTD_ext_CSS_XML_DEMO_catalog.xml , DTD_external_catalog.dtd and library.css

  • 7/28/2019 XML prog

    3/11

    XML BibleWinstonWiely Fourth0-2345-2345-9Rs. 400

    Java Complete ReferenceHerbert ShieldTMH Fourth0-2345-2345-11Rs. 480

    Introduction to Web technologyAkhilesh Kumar SinghTech MaxThird

    0-2345-2345-13Rs. 350

    Introduction to CReema TharejaOrfordSecond0-2345-2345-14Rs. 300

    DTD_external_catalog.dtd

    6. Program for Schema named as stuschema.xsd and stuschema.xml

    stuschema.xsd

  • 7/28/2019 XML prog

    4/11

    stuschema.xml

    AnandNew Delhithird89 Percent

    7. Program for Restricted Schema named as schema_restr.xsd andschema_restr.xmlschema_restr.xsd

  • 7/28/2019 XML prog

    5/11

    try{

    xmldoc.async=false;xmldoc.load("stusdent.xml");document.write("XML Document student.xml is loaded");

    }catch(e){

    alert(e.message)

    }

    9. Program of document object model(Parsing the XML document using text)named as domtext.html.

    m_text=""

    m_text=m_text+"10";m_text=m_text+"";m_text=m_text+"Anand";m_text=m_text+"New Delhi";m_text=m_text+"89 Percent";m_text=m_text+"";m_text=m_text+"Second";m_text=m_text+"Maths";m_text=m_text+"100";m_text=m_text+""try{

    xmldoc=new ActiveXObject("Microsoft.XMLDOM");xmldoc.async=false;xmldoc.loadXML(m_text);

    }catch(e){

    try{

    parser=new DOMParser();xmldoc=parser.parseFromString(m_text, "text/xml");

    }catch(e)

    {alert(e.message)

    }}try{

    document.write("XML Document student.xml is loaded with text");}catch(e){

    alert(e.message)

  • 7/28/2019 XML prog

    6/11

    }10. Program of document object model (use of separate function for loading an

    XML file) named as domloadfunc.html and student.xml.

    function My_Function(doc_file){try{

    xmldoc=new ActiveXObject("Microsoft.XMLDOM");}catch(e){

    try{

    xmldoc=document.implementation.createDocument("","",null);

    }catch(e){

    alert(e.message)}

    }try{

    xmldoc.async=false;xmldoc.load(doc_file);return(xmldoc);

    }

    catch(e){

    alert(e.message)}return(null);}xmldoc=My_Function("stusdent.xml");document.write("XML Document student.xml is loaded");

    11. Program of document object model (Storing the separate function externalfile) named as domloadext.html , my_function_file.js and student.xml.

    domloadext.html

  • 7/28/2019 XML prog

    7/11

    xmldoc=My_Function("stusdent.xml");document.write("XML Document student.xml is loaded");

    my_function_file.js

    function My_Function(xml_doc_file){try{

    xmldoc=new ActiveXObject("Microsoft.XMLDOM");}catch(e){

    try{

    xmldoc=document.implementation.createDocument("","",null);

    }catch(e){

    alert(e.message)}

    }try{

    xmldoc.async=false;xmldoc.load(xml_doc_file);return(xmldoc);

    }

    catch(e){

    alert(e.message)}return(null);}

    12. XML Program for properties and Method and the program named arestudent.xml, domprop_method.html

    student.xml

    10

    AnandNew Delhi89 Percent

    SecondMaths100

    11

  • 7/28/2019 XML prog

    8/11

    Anil Delhi90Percent

    ThirdEnglish89

    12

    AmmarVaranasi97 Percent

    FifthUrdu38

    domprop_method.html

    xmldoc=My_Function("student.xml");document.write("XML document is loaded and following are content of this file");document.write("");for(i=0;i

  • 7/28/2019 XML prog

    9/11

    13. Program for XSL Stylesheet. Program named are Simplexml.xml andSimplexml.xsl

    Simplexml.xml

    AnandNew Delhithird89 Percent

    AnilVaranasiSecond79 Percent

    SunilGaziabadFirst80 Percent

    Yatharth RatneshNew DelhiFifth90 Percent

    simplexml.xslStudent Database

    NameAddressStanderdMarks

  • 7/28/2019 XML prog

    10/11

    14. Program for Processor DOM API to check well formedness of XML document.Program named is Parsing_DOM.java

    import java.io.*;import javax.xml.parsers.*;import org.w3c.dom.*;import org.xml.sax.*;

    public class Parsing_DOM{

    public static void main(String a[]) throws IOException{

    try{

    System.out.println("Enter the name of XML Document");BufferedReader br=new BufferedReader(new

    InputStreamReader(System.in));String fname=br.readLine();File fp=new File(fname);if(fp.exists()){

    try{

    DocumentBuilderFactory

    dbf=DocumentBuilderFactory.newInstance();DocumentBuilder db=dbf.newDocumentBuilder();InputSource src=new InputSource(fname);Document doc=db.parse(src);System.out.println(fname +" is well formed");

    }catch(Exception e){

    System.out.println(fname +" is not well formed");System.exit(1);

    }}

    else{

    System.out.println("File not found");}

    }catch(IOException ex){

    ex.printStackTrace();}

    }}

  • 7/28/2019 XML prog

    11/11

    15. Program for Processor SAX API to check well formedness of XML document.Program named is Parsing_SAX.java

    import java.io.*;import org.xml.sax.*;import org.xml.sax.helpers.*;

    public class Parsing_SAX{

    public static void main(String a[])

    {try{

    System.out.println("Enter the name of XML Document");BufferedReader br=new BufferedReader(new

    InputStreamReader(System.in));String fname=br.readLine();File fp=new File(fname);if(fp.exists()){

    try{

    XMLReader xr=XMLReaderFactory.createXMLReader();xr.parse(fname);System.out.println(fname + " is well formed");

    }catch(Exception e){

    System.out.println(fname +" well not formed");System.exit(1);

    }}else

    {System.out.println("File not found");

    }}catch(IOException ex){

    ex.printStackTrace();}

    }}