XMLConstants.W3C_XML_SCHEMA_NS_URI : XMLConstants « javax.xml « Java by API

Home
Java by API
1.com.sun.image.codec.jpeg
2.java.applet
3.java.awt
4.java.awt.datatransfer
5.java.awt.dnd
6.java.awt.event
7.java.awt.font
8.java.awt.geom
9.java.awt.im.spi
10.java.awt.image
11.java.awt.print
12.java.beans
13.java.beans.beancontext
14.java.io
15.java.lang
16.java.lang.annotation
17.java.lang.instrument
18.java.lang.management
19.java.lang.ref
20.java.lang.reflect
21.java.math
22.java.net
23.java.nio
24.java.nio.channels
25.java.nio.charset
26.java.rmi.dgc
27.java.rmi.server
28.java.security
29.java.security.cert
30.java.security.spec
31.java.sql
32.java.text
33.java.text.spi
34.java.util
35.java.util.concurrent
36.java.util.concurrent.atomic
37.java.util.concurrent.locks
38.java.util.jar
39.java.util.logging
40.java.util.prefs
41.java.util.regex
42.java.util.spi
43.java.util.zip
44.javax.accessibility
45.javax.activation
46.javax.annotation.security
47.javax.comm
48.javax.crypto
49.javax.crypto.spec
50.javax.ejb
51.javax.imageio
52.javax.imageio.event
53.javax.jws
54.javax.mail
55.javax.mail.internet
56.javax.media.jai
57.javax.microedition.io
58.javax.microedition.lcdui
59.javax.microedition.media
60.javax.microedition.media.control
61.javax.microedition.midlet
62.javax.microedition.pim
63.javax.microedition.rms
64.javax.naming
65.javax.naming.directory
66.javax.naming.event
67.javax.naming.ldap
68.javax.naming.spi
69.javax.net
70.javax.net.ssl
71.javax.persistence
72.javax.print
73.javax.print.attribute
74.javax.print.attribute.standard
75.javax.print.event
76.javax.script
77.javax.servlet
78.javax.servlet.http
79.javax.sound.midi
80.javax.sound.sampled
81.javax.sql
82.javax.sql.rowset
83.javax.swing
84.javax.swing.border
85.javax.swing.colorchooser
86.javax.swing.event
87.javax.swing.filechooser
88.javax.swing.plaf.basic
89.javax.swing.plaf.metal
90.javax.swing.plaf.synth
91.javax.swing.table
92.javax.swing.text
93.javax.swing.text.html
94.javax.swing.text.html.parser
95.javax.swing.text.rtf
96.javax.swing.tree
97.javax.swing.undo
98.javax.tools
99.javax.transaction
100.javax.xml
101.javax.xml.bind
102.javax.xml.bind.annotation
103.javax.xml.crypto.dsig
104.javax.xml.crypto.dsig.keyinfo
105.javax.xml.namespace
106.javax.xml.parsers
107.javax.xml.soap
108.javax.xml.stream
109.javax.xml.stream.events
110.javax.xml.transform
111.javax.xml.transform.dom
112.javax.xml.transform.stream
113.javax.xml.validation
114.javax.xml.ws
115.javax.xml.xpath
116.junit.extensions
117.junit.framework
118.junit.textui
119.org.apache.commons.lang
120.org.apache.commons.lang.builder
121.org.apache.commons.lang.exception
122.org.apache.commons.lang.time
123.org.apache.commons.logging
124.org.apache.commons.math
125.org.eclipse.jface.action
126.org.eclipse.jface.dialogs
127.org.eclipse.jface.operation
128.org.eclipse.jface.viewers
129.org.eclipse.jface.window
130.org.eclipse.jface.wizard
131.org.eclipse.swt
132.org.eclipse.swt.browser
133.org.eclipse.swt.custom
134.org.eclipse.swt.dnd
135.org.eclipse.swt.events
136.org.eclipse.swt.graphics
137.org.eclipse.swt.layout
138.org.eclipse.swt.ole.win32
139.org.eclipse.swt.printing
140.org.eclipse.swt.program
141.org.eclipse.swt.widgets
142.org.junit
143.org.w3c.dom
144.org.xml.sax
145.org.xml.sax.helpers
146.sun.audio
Java by API » javax.xml » XMLConstants 
XMLConstants.W3C_XML_SCHEMA_NS_URI
 

/*
Parser object is: com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl@c9ba38
Start document: 
Start element: local name: PHONEBOOK qname: PHONEBOOK uri: 
Characters:   
Start element: local name: PERSON qname: PERSON uri: 
Characters:    
Start element: local name: NAME qname: NAME uri: 
Attributes:
  Name : firstName
  Type : CDATA
  Value: Joe
  Name : lastName
  Type : CDATA
  Value: Yin
Characters: Joe
Characters:  Yin
End element: local name: NAME qname: NAME uri: 
Characters:    
Start element: local name: EMAIL qname: EMAIL uri: 
Characters: joe@yourserver.com
End element: local name: EMAIL qname: EMAIL uri: 
Characters:    
Start element: local name: TELEPHONE qname: TELEPHONE uri: 
Characters: 202-999-9999
End element: local name: TELEPHONE qname: TELEPHONE uri: 
Characters:    
Start element: local name: WEB qname: WEB uri: 
Characters: www.java2s.com
End element: local name: WEB qname: WEB uri: 
Characters:   
End element: local name: PERSON qname: PERSON uri: 
Characters:   
End element: local name: PHONEBOOK qname: PHONEBOOK uri: 
End document: 
 */
import java.io.StringReader;

import javax.xml.XMLConstants;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.SchemaFactory;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

public class MainClass {
  public static void main(String args[])throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser parser = null;
    spf.setNamespaceAware(true);
    try {
     SchemaFactory sf =
                     SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
     spf.setSchema(sf.newSchema(new SAXSource(new InputSource(new StringReader(schemaString)))));

     parser = spf.newSAXParser();
    }
    catch(SAXException e) {
      e.printStackTrace(System.err);
      System.exit(1);    
    
    catch(ParserConfigurationException e) {
      e.printStackTrace(System.err);
      System.exit(1);    
    }
    MySAXHandler handler = new MySAXHandler()
    System.out.println(schemaString);
    parser.parse(new InputSource(new StringReader(xmlString)), handler);
  }
  static String xmlString = "<?xml version=\"1.0\"?>" +
      "<note>" +
      "<to>rtoName</to>" +
      "<from>FromName</from>" +
      "<heading>Info</heading>" +
      "<body>Message Body</body>" +
      "</note>";
  
  static String schemaString ="<?xml version=\"1.0\"?>" +
      "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" +
      " targetNamespace=\"http://www.java2s.com\"" +
      " xmlns=\"http://www.java2s.com\"" +
      " elementFormDefault=\"qualified\">" +
      "<xs:element name=\"note\">" +
      "<xs:complexType>" +
      "<xs:sequence>" +
      "<xs:element name=\"to\" type=\"xs:string\"/>" +
      "<xs:element name=\"from\" type=\"xs:string\"/>" +
      "<xs:element name=\"heading\" type=\"xs:string\"/>" +
      "<xs:element name=\"body\" type=\"xs:string\"/>" +
      "</xs:sequence>" +
                      "</xs:complexType>" +
                      "</xs:element>" +
                      "</xs:schema>";
}

class MySAXHandler extends DefaultHandler {
  public void startDocument() {
    System.out.println("Start document: ");
  }    
    public void endDocument()  {
    System.out.println("End document: ");
  }
  
  public void startElement(String uri, String localName, String qname, 
                                                               Attributes attr)
  {
    System.out.println("Start element: local name: " + localName + " qname: " 
                                                        + qname + " uri: "+uri);
    int attrCount = attr.getLength();
    if(attrCount>0) {
      System.out.println("Attributes:")
      for(int i = ; i<attrCount ; i++) {
        System.out.println("  Name : " + attr.getQName(i))
        System.out.println("  Type : " + attr.getType(i))
        System.out.println("  Value: " + attr.getValue(i))
      }
    
  }
  
  public void endElement(String uri, String localName, String qname) {
    System.out.println("End element: local name: " + localName + " qname: "
                                                         + qname + " uri: "+uri);
  }
  
  public void characters(char[] ch, int start, int length) {
    System.out.println("Characters: " new String(ch, start, length));
  }

  public void ignorableWhitespace(char[] ch, int start, int length) {
    System.out.println("Ignorable whitespace: " new String(ch, start, length));
  }

  public void startPrefixMapping(String prefix, String uri) {
    System.out.println("Start \"" + prefix + "\" namespace scope. URI: " + uri)
  }

  public void endPrefixMapping(String prefix) {
    System.out.println("End \"" + prefix + "\" namespace scope.")
  }

  public void warning(SAXParseException spe) {
    System.out.println("Warning at line "+spe.getLineNumber());
    System.out.println(spe.getMessage());
  }

  public void fatalError(SAXParseException spethrows SAXException {
    System.out.println("Fatal error at line "+spe.getLineNumber());
    System.out.println(spe.getMessage());
    throw spe;
  }
}


           
         
  
Related examples in the same category
1.XMLConstants.XMLNS_ATTRIBUTE
2.XMLConstants.XML_NS_PREFIX
3.XMLConstants.XML_NS_URI
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.