XSD size and Java XML Parsers (specifically SAX)

Does the size of XSD matter in terms of performace runtime. I would like to create an XSD as one contract that houses all non-mandatory elements so the resulting xml out of this will use similar structure but wont use all of the XSD elements.
Is there a problem with such an XSD which will be 1000 or more elements as far as Java parsing is concerned
Pl. let me knwo thanks

I do a lot of work with an international standard -- S1000D -- for documentation and technical manuals. It has 58 schema files (10 that are main files that are referenced by an XML file, and the other 48 get imbedded as needed). It does not slow down the parsing of files by any noticable amount.
Dave Patterson

Similar Messages

  • Differnce between java script xml dom and Java Xml dom

    Hi,
    In my application For client side in Java Script for craetion of DOM MIcrosoft Activex object is used. USing that one they are buiidng DOM. And they are saving as XML. In server side i have to write one servlet which will parse that xml and i have to store in dynamic arrays.Which API is better for parsing XML in java.In util pacakge which class is better for storing dynamical values that means MAP,Hash Map,Hash table ??

    in java, the java..xml.parsers package is generally used for parsing xml into a DOM. there are also sax and stax parsers available.
    which class in java.util is better for storing stuff depends on what you need to do with the stuff. find a nice tutorial on java collections and then decide which one makes sense for what you need.

  • Java XML parsers for Sun J2ME, Sun KVM

    Here is a list of "small" XML parsers.
    Some are specifically for the J2ME platform / Sun KVM:
    kXML
    http://kxml.enhydra.org/
    NanoXML
    http://nanoxml.sourceforge.net/
    TinyXML
    http://www.gibaradunn.srac.org/tiny/index.shtml
    MinML
    http://www.wilson.co.uk/xml/minml.htm
    XMLtp
    http://sourceforge.net/projects/jxmltp/
    Al Sutton XML parser
    http://sourceforge.net/projects/asxmlp/
    Also:
    JSR 118 is a specification for the "Mobile Information Device
    Next Generation"
    http://www.jcp.org/jsr/detail/118.jsp
    The JSR 118 group is considering adding a "small, efficient XML parser to enable platform-independent data exchange" to MIDP.

    Fastparser is a 25Ko parser : http://www.japisoft.com/fastparser
    Best regards,
    A.Brillant

  • PLSQL and Java XML type mapping

    Running database 10gR2.  Trying to create a Java stored procedure that returns an XML type (oracle.xdb.XMLType) like so:
    class MyCoolClass
       static oracle.xdb.XMLType doSomething( String xmldata)
         oracle.xdb.XMLType xmlt = new oracle.xdb.XMLType( xmldata );
         return xmlt;
    This, of course, is wrapped by a PL/SQL function:
    function doSomething( xmldata varchar2 ) return SYS.XMLTYPE AS LANGUAGE JAVA
    name 'MyCoolClass.doSomething(java.lang.String) return oracle.xdb.XMLType';
    While everything compiles (that means it should work, right?), the above codes generates a runtime error ORA-00932 'inconsistent datatypes' error.   I'm not  sure what I'm doing wrong, it was my understanding that a default mapping existed between the PL/SQL SYS.XMLTYPE and oracle.xdb.XMLType.  Is what I'm attempting even possible?

    Sorry, I was being sloppy with my code example.  It should be:
    class MyCoolClass
       static oracle.xdb.XMLType doSomething( String xmldata)
          java.sql.Connection c = java.sql.DriverManager.getConnection("jdbc:default:connection:");
         oracle.xdb.XMLType xmlt = new oracle.xdb.XMLType( c, xmldata );
         return xmlt;

  • Screen Size and Java?

    Hi
    I'm newbie in Java language.
    I'm creating a game to run on every mobile fone that support Java, this game will have pictures (.png).
    So my two questions are:
    -When a launch my game i have to know if the mobile support Java?and if so is there any library or class or other way to know if that mobile support java?
    -The screen size varies from mobile to mobile, through the method getHeight() and getWidth() i get the mobile resolution, when i create the pictures i have to create them to a standard size? is there any standard resolution to mobile fone?
    Best regards
    Luis
    [email protected]

    So my two questions are:
    -When a launch my game i have to know if the mobile
    support Java?and if so is there any library or class
    or other way to know if that mobile support java?If the phone does not support java, the app will not run ;)
    -The screen size varies from mobile to mobile,
    through the method getHeight() and getWidth() i get
    the mobile resolution, when i create the pictures i
    have to create them to a standard size? is there any
    standard resolution to mobile fone?No standard resolution. There are a few resolutions that are often used though. You might look into that.

  • Ciscoworks and Java - requiring a specific version

    Can anyone explain why Ciscoworks requires a specific version of the java plugin rather than just using it as a minimum requirement? The current version of java is 1.5.0_01 but when I access our server it complains that I'm not running 1.4.1_02. Is there anyway to stop this check happening and to force it to just use what's installed?
    cheers
    Mike

    Why indeed. I have raised this to Cisco developers ad nauseum. They are moving to more of a pure html schema with the upcoming release of LMS. Even that, though, will still have dependency on a specific JRE (1.42_something if I recall correctly). For now, you can use the parts of LMS and RWAN that aren't java-based applets despite the suite's error warning. Using any of the java applets (CiscoView, Campus Manager, etc.) requires the exact JRE noted in the documentation (1.41_02) and no substitutes are accepted. This is hard coded in the applet and there is no reliable work around. Some have reported limited success by using the Java control panel and having multiple JREs loaded on their machine. This is a bit tricky though and may not work in all situations.
    Thus the great myth of Java (write once, run anywhere) is exposed. The cynic might observe that a MS-based implementation would be prefereble. the purist would opine that a pure html W3C-compliant app would be the way to go. The realist just sighs and goes about working with what he (or she) is given.

  • Is java.xml.parsers.DocumentBuilder Thread Safe?

    Does anyone know if the DocumentBuilder is thread safe? Meaning,
    can I call the parse(...) methods from several threads simultanously, without getting errors?
    I would be happy if anyone can also point me to the documentation that says DocumentBuilder is or isn't thread safe.

    My Code Like Such:
    public class DigestUtil
    private static MessageDigest md_md5 = null;
    static
    try{
    md_md5 = MessageDigest.getInstance("MD5");
    }catch(Exception ex)
    public static byte[] DigestMD5(byte[] b)
    return b==null ? null : md_md5.digest(b);
    I Don't Wish to Every Digest, Every Create MessageDigest Instance.

  • Java XML-Reader (SAX)--How to read and display xml-element-data???

    hello all,
    i would like to display just some xml-data
    Which methods in java should i use to select just one character-data of this (for example: "deu" from the element <Language> or the attribut "version" of the element <catalog>).
    Here is the XML-document i want to parse and display it with System.out.print() :
    <BMECAT version="1.2">
         <HEADER>
              <GENERATOR_INFO>
                   e-proCat 2.1, e-pro solutions GmbH
              </GENERATOR_INFO>
              <CATALOG>
                   <LANGUAGE>deu</LANGUAGE>
                   <CATALOG_ID>Katalog 01</CATALOG_ID>
                   <CATALOG_VERSION>001.000</CATALOG_VERSION>
                   <CATALOG_NAME>ETIM</CATALOG_NAME>
                   <DATETIME type="generation_date">
                        <DATE>2002-05-22</DATE>
                   </DATETIME>
                   <TERRITORY>DE</TERRITORY>
                   <CURRENCY>EUR</CURRENCY>
                   <MIME_ROOT>ETIM-Daten</MIME_ROOT>
              </CATALOG>
    </HEADER>
    </BMECAT>
    Here is the java application i wrote and which doesn t work:
    import org.apache.xerces.parsers.SAXParser;
    import org.xml.sax.Attributes;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.Locator;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
         public class XmlLeser implements ContentHandler {
    public XmlLeser(String fileName) {
    try {
    XMLReader myParser = new SAXParser(); // SAXParser (Xerces)
    myParser.setContentHandler(this);           
    myParser.parse(fileName);      } catch (Exception e) {
         System.out.println("Erreur " + e);     }
    }// End of constructor
    public void startDocument() {
         System.out.println(" start to parse " );
    } // startDocument()
    public void endDocument() {
    System.out.println(" End of Parse ");
    } // endDocument()
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
         System.out.println(localName) ;
    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {           
    }// Endelement()
    public void characters(char ch[], int start, int length) {
    } // endCharacters(char[],int,int);
    public void processingInstruction(String target, String data) {
    } // processingInstruction(String,String)
    public void ignorableWhitespace(char ch[], int start, int length) {
              characters(ch, start, length);
    } // ignorableWhitespace(char[],int,int);
    public static void main(String args[]) {
    String xmlFileName = "";
    if (args.length == 0) {               
    System.out.println("Usage::java XmlLeser path/xmlFilename");
    System.exit(0);      } else {
    xmlFileName = args[0];
    XmlLeser pux = new XmlLeser(xmlFileName);
    }// end main()
    }//endClass

    You need to pass your filename String as a parameter to your functionality. It depends how you're currently set up though. We can't really see the top of your call so it's difficult to determine what you are calling and we don't really know from where you're calling either.
    If you're running standalone, then on launch of the application, you can feed in a file name as an argument that you can read in in String args[] in the main function and pass down to your XML splitter.
    If you're a method in a class that's part of a bigger pile, you can feed the file name as a String to the method from wherever you call from if it makes sense architecturally.
    You might also want to pass down a File object if that makes sense in your current code (i.e. if you're using your file for other purposes prior to the split, to avoid recreating closing/opening for no reason).
    Depends what you're trying to do. If I put together a piece like this, I would probably create an <yourcurrentrootpackage>.xml.splitter package.
    Also, on a side note, you're problem isn't really reading and writing XML in java, but seems more to be making your functionality generic so that any XML file can be split with your code.
    Regards
    JFM

  • Java XML and podcasts

    Hi all,,
    Im just looking for some help with a java xml passer program. Im trying to create a program that will read specific tags and the values that are represented by these tags in the xml file..I have found the following code
    import java.io.File;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    public class ReadAndPrintXMLFile{
    public static void main (String argv []){
    try {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse (new File("book.xml"));
    // normalize text representation
    doc.getDocumentElement ().normalize ();
    System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName());
    NodeList listOfPersons = doc.getElementsByTagName("person");
    int totalPersons = listOfPersons.getLength();
    System.out.println("Total no of people : " + totalPersons);
    for(int s=0; s<listOfPersons.getLength() ; s++){
    Node firstPersonNode = listOfPersons.item(s);
    if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
    Element firstPersonElement = (Element)firstPersonNode;
    NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
    Element firstNameElement = (Element)firstNameList.item(0);
    NodeList textFNList = firstNameElement.getChildNodes();
    System.out.println("First Name : " + ((Node)textFNList.item(0)).getNodeValue().trim());
    NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
    Element lastNameElement = (Element)lastNameList.item(0);
    NodeList textLNList = lastNameElement.getChildNodes();
    System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
    NodeList ageList = firstPersonElement.getElementsByTagName("age");
    Element ageElement = (Element)ageList.item(0);
    NodeList textAgeList = ageElement.getChildNodes();
    System.out.println("Age : " + ((Node)textAgeList.item(0)).getNodeValue().trim());
    }//end of if clause
    }//end of for loop with s var
    }catch (SAXParseException err) {
    System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
    System.out.println(" " + err.getMessage ());
    }catch (SAXException e) {
    Exception x = e.getException ();
    ((x == null) ? e : x).printStackTrace ();
    }catch (Throwable t) {
    t.printStackTrace ();
    //System.exit (0);
    }//end of main
    }Im trying to develop this code to work with podcast xml files..Im having a few issuses with this program.. Is there anyone out there that has created a program like this that works with podcast xml files??
    Anyone got any suggestions.Please.

    XML and XSL transformations can be done using most languages and in Java there is strong support for these techniques.
    It worries me a little bit that you ask this question though. XML and XSL are no more than a tool to solve SOME problems, but I get the idea that you want to put them on your resume as if they are your main talent. The tool set of the developer is much broader than just some techniques to format and transform data, you need to be able to solve problems in the most efficient way possible, not limiting yourself to only a handful of techniques that you just happen to know a lot about.
    What I am trying to say is: it is always good to have knowledge of these techniques, but don't go thinking it is going to guarantee you a job.

  • HOWTO: Writing Out XML Query Results of Any Size in Java with XML SQL Utility

    A customer mailed me asking for an example of how to use our XML SQL Utility to write out query results for tons of query result rows.
    With tons of data, the getXMLDOM() and getXMLString() methods are not really appropriate due to the size.
    The XML SQL Utility offers a getXMLSAX() method that streams SAX2 events to report the data being queried. This is the approach we can use to handle data of any size.
    It dawned on me today that by putting together the XML SQL Utilities getXMLSAX() routine, and the oracle.xml.parser.v2.XSLSAXPrintDriver SAX2 ContentHandler, we can effectively stream out data of any length to an appropriate writer.
    Here's a code example to get the point across:
    package test;
    import java.io.BufferedOutputStream;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Properties;
    import javax.xml.transform.OutputKeys;
    import oracle.jdbc.OracleDriver;
    import oracle.xml.parser.v2.XSLException;
    import oracle.xml.parser.v2.XSLOutput;
    import oracle.xml.parser.v2.XSLSAXPrintDriver;
    import oracle.xml.sql.query.OracleXMLQuery;
    public class Example  {
      private static final String QUERY = "select * from emp";
      public static void main(String[] args) throws Throwable  {
          Connection conn = getConnection();
          OracleXMLQuery q = new OracleXMLQuery(getConnection(),QUERY);
          // Any printwriter will do. Here's we're output to standard out.
          PrintWriter output = new PrintWriter(new BufferedOutputStream(System.out));
          // This is a SAX2 Content Handler used by the Oracle XSLT Engine
          // to serialize a stream of sax2 events as an XML document
          // We'll use it to serialize the sax2 events from the XML SQL Utility
          // out as an XML document.
          XSLSAXPrintDriver ch = new XSLSAXPrintDriver(output, outputOptions());  
          // This asks XML SQL Utility to fire sax events for the data
          // being fetched instead of creating DOM nodes or returning text.
          // By using the XSLSAXPrintDriver content handler, these events
          // get handled by writing them directly to the output stream
          q.getXMLSAX(ch);
          ch.flush();
          q.close();
          conn.close();     
      private static XSLOutput outputOptions() throws XSLException {
        XSLOutput x = new XSLOutput();
        Properties props = new Properties();
        props.put(OutputKeys.METHOD,"xml");
        props.put(OutputKeys.INDENT,"yes");  // Set to "no" for non-indented
        x.setProps(props);
        return x;
      public static Connection getConnection() throws SQLException {
        String username = "scott";
        String password = "tiger";
        String thinConn = "jdbc:oracle:thin:@localhost:1521:ORCL";
        Driver d = new OracleDriver();
        return DriverManager.getConnection(thinConn,username,password);
    }

    Hi Uber,
    This is a known issue that error occurs when running report "Count of instances of specific software registered with Add or Remove Programs" due to non-printable characters for XML. Based on internal research, the hotfix for this issue will be
    included in the System Center 2012 Configuration Manager Service Pack 1.
    As a workaround, you can remove the nonprintable character populated into the report parameter by referring to the following KB article:
    http://support.microsoft.com/KB/914159
    Hope this helps.
    Regards,
    Mike Yin
    Mike Yin
    TechNet Community Support

  • How use XSD and Java? What classes/methods?

    I want to use an XSD instead of a DTD with my XML and Java. Does anyone know the classes/methods I should use to do this? Is it even possible? Can you send sample code?

    here is the helper function... hope it helps...
    import java.io.IOException;
    import java.math.*;
    import java.text.*;
    import org.xml.sax.Attributes;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.Locator;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.XMLReaderFactory;
    public class SAXParserDemo
         public SAXParserDemo()
         public void performDemo(String uri)
              System.out.println("Parsing XML file: " + uri + "\n\n");
              ContentHandler contentHandler = new MyContentHandler();
              ErrorHandler errorHandler = new MyErrorHandler();
              try
                   XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
                   parser.setContentHandler(contentHandler);
                   parser.setErrorHandler(errorHandler);
                   parser.setFeature("http://xml.org/sax/features/validation", true);
                   parser.parse(uri);
              catch(IOException e)
                   System.out.println("Error reading URI: " + e);
              catch(SAXException e)
                   System.out.println("Error in parsing: " + e);
         public static void main(String[] args)
              if(args.length != 1)
                   System.out.println("Usage: java SAXParserDemo [XML URI]");
                   System.exit(0);
              String uri = args[0];
              SAXParserDemo parserDemo = new SAXParserDemo();
              parserDemo.performDemo(uri);
    class MyErrorHandler implements ErrorHandler
         public void warning(SAXParseException exception) throws SAXException
              throw new SAXException("Warning encountered."+exception);
         public void error(SAXParseException exception) throws SAXException
              throw new SAXException("Error encountered: "+exception);
         public void fatalError(SAXParseException exception) throws SAXException
              throw new SAXException("Fatal error encountered."+exception);
    class MyContentHandler implements ContentHandler
         private Locator locator;
         public void setDocumentLocator(Locator locator)
              //System.out.println("     * setDocumentLocator() called");
              this.locator = locator;
         public void startDocument() throws SAXException
              //System.out.println("System Message: Parsing begins...");
         public void endDocument() throws SAXException
              //System.out.println("System Message: ...Parsing ends.");
         public void processingInstruction(String target, String data) throws SAXException
              //System.out.println("System Message: PI: Target: "+target+" and Data: "+data);
         public void startPrefixMapping(String prefix, String uri)
              //System.out.println("System Message: Mapping starts on prefix "+prefix+" mapped to URI "+uri);
         public void endPrefixMapping(String prefix)
              //System.out.println("System Message: Mapping ends on prefix "+prefix);
         public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException
              //System.out.println("System Message: startElement: "+localName);
              if(!namespaceURI.equals(""))
                   //System.out.println("System Message: in namespace "+namespaceURI+" ("+rawName+")");
              else
                   //System.out.println("System Message: has no associated namespace");
              int i;
              for(i=0;i<atts.getLength();i++)
                   //System.out.println("System Message: Attribute: "+atts.getLocalName(i)+"="+atts.getValue(i));
         public void endElement(String namespaceURI, String localName, String rawName) throws SAXException
              //System.out.println("System Message: endElement: "+localName+"\n");
         public void characters(char[] ch, int start, int length) throws SAXException
              String s = new String(ch, start, length);
              //System.out.println("System Message: characters: "+s);
         public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
              String s = new String(ch, start, length);
              //System.out.println("System Message: ignorableWhitespace: ["+s+"]");
         public void skippedEntity(String name) throws SAXException
              //System.out.println("System Message: Skipping entity: "+name);
    }

  • Experiences with Adobe XPAAJ, XML Parsers, OC4J /AS 10.1.2,10.1.3 and DB10g

    Over the past couple of weeks we have been working on a solution which uses the newly available adobe XPAAJ api's (XML/PDF Access API for Java) for Java.
    The client has a legacy requirement to where users are issued with a pdf form which they complete, save and upload to the server via a JSP. A neat bit of Java code utilizing the XPAAJ API's then strips out the form entered data and spits out XML. This is then parsed and inserted into relational tables within the schema.
    Our solution needs to be deployed to an Oracle stack. However we ran into a number of problems when deploying the solution to AS 10.1.2. The adobe API's are not compatible with the Oracle XML Parsers. When extracting the form data, no error is reported and the code which performs the xml parsing just fails. Very nasty.
    The main problem has been that Oracle XDK libraries have been hard-coded into the classpath of the container using the referential JAR file Class-Path mechanism. Altering this has required the use of the JRE extension library mechanism, or altering the boot classpath of the JVM when it is launched to load the alternative XML parser implementation instead. While this works, it has been an unsupported operation since the effect of this change is not limited to a specific application – it’s effect are felt across the entire container and this may lead to unpredictable results at runtime.
    ~http://www.oracle.com/technology/tech/java/oc4j/10131/how_to/how-to-swapxmlparser/doc/readme.html
    We did look at a number of other solutions including embedding the java classes I'd written into the database. After loading the apache Xerces api's into our schema we hit upon the same problem. It seems that the same thing happens in the database and the Oracle XML parser is used by default.. Please see SR Number : 6153038.994 on Metalink.
    If you can upgrade to AS 10.1.3 then you can follow the excellent how to at:http://www.oracle.com/technology/tech/java/oc4j/10131/how_to/how-to-swapxmlparser/doc/readme.html . Demo code can be found at: http://www.oracle.com/technology/tech/java/oc4j/10131/how_to/how-to-swapxmlparser/how-to-swapxmlparser.zip
    The how-to details how to swap xml parsers within the application server.
    Other possible solutions that are also available include:
    - Shelling out to the OS from the DB or Apps Server, You can then execute the app as a command line app with a custom classpath. Very bad architecture design.
    - Setting up an RMI client / server application where client is the db or apps server. You can find examples of this on the web. google 'Simple RMI example'.
    - Bootstrapping the XML parser in AS 10.1.2 (unsupported).
    I hope people have found this informative. It might save someone a lot of time.
    Message was edited by:
    Kris Jones

    "When I was installing SOA 10.1.3.1.0 on oracle 10.2.0.1 and it was giving error that it needs minimum 10.2.0.3, just wondering 10.1.2.0.2 + SOA =will this work?"
    so you talk about the db version. SOA 10.1.3.x runs on 10.2.0.1 and above (I ran for the longest time on XE) and if I remember correctly that's a warning, and not a hard prereq.
    Regarding Appserver versions - soa 10.1.3 runs on AS 10.1.3 only

  • Java enhancement in XSLT mapping in PI 7.1 and JDK5 XML processing

    Hi,
    I am implementing an XSLT mapping and I need to use java enhancements. I got those working but only if I check "Use SAP XML Toolkit" from Operation Mapping. I would like to use JDK5 XML processing.
    I also got this message to trace:
    Resource not found: META-INF/services/javax.xml.parsers.SAXParserFactory
    Thrown:
    com.sap.aii.ib.server.mapping.execution.MappingClassNotFoundException: META-INF/services/javax.xml.parsers.saxparserfactory
    I tried to use com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl but still couldn't get java enhancement working.
    Is there a way to get JDK5 XML processing working with java enhancements?

    > Is there a way to get JDK5 XML processing working with java enhancements?
    No. Java processing inside XSLT is no standard. So it works only with SAP lib.
    Regards
    Stefan

  • Java.lang.NullPointerException javax.xml.parsers.DocumentBuilder.parse

    Hi all,
    i have a problem by solving an error in my code. The Code is mainly from Ian Darwin.
    The code i am running works with j2sdk1.4.2_04. But now i have to bring it to work with jdk1.6.0_13.
    The code parses xml documents. With small xml documents the code works. With large xml documents i get the following error while running the produced class file.
    Exception in thread "main" java.lang.NullPointerException
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex(DeferredDocumentImpl.java:1944)
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild(DeferredDocumentImpl.java:644)
    at com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters(AbstractDOMParser.java:1191)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters(XMLDTDValidator.java:862)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:463)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
    at XParse.parse(XParse.java:38)
    at XParse$JFileChooserrv.<init>(XParse.java:119)
    at XParse.main(XParse.java:213)
    I know what a java.lang.NullPointerException mens. But i don't know where i have to look for. Specially i don't know what or where "com.sun.org.apache...." is.
    Is there a package that a have to add to the environment? Can some one tell my where i can find this package?
    I wrote the code for some years ago, 2006 or so. With the knew jdk1.6.0_13 some thinks chance in the environment. Couldn't find what exactly.
    The code has only 215 lines, but some how i can't add it to this Message, because Maximum allowed is only 7500.
    Is there an other Forum, which may is better for my question?

    Here is the code:
    import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.Container;
    import javax.swing.JTextArea;
    * This code is mainly from @author Ian Darwin, [email protected]
    public class XParse {
         /** Convert the file */
         public static void parse(File file, boolean validate) {
              try {
                   System.err.println("");
                   String fileName = file.getAbsolutePath();
                   System.err.println("Parsing " + fileName + "...");
                   // Make the document a URL so relative DTD works.
                   //String uri = new File(fileName).getAbsolutePath();
                   //System.err.println(uri);
                   DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
                   if (validate)
                   f.setValidating(true);
                   DocumentBuilder p = f.newDocumentBuilder();
                   p.setErrorHandler(new MyErrorHandler(System.err));
                   //XmlDocument doc = XmlDocument.createXMLDocument(file);
                   boolean vaild =  p.isValidating();
                   if (vaild) {
                        System.out.println("yes parsing");
                        Document doc = p.parse(file); // <<<< ERROR
                   System.out.println("Parsed OK");
              } catch (SAXParseException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("At line " + ex.getLineNumber());
                   System.err.println("+================================+");
              } /**catch (RuntimeException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   //System.err.println("At line " + ex.getLineNumber());
                   //System.err.println("At line " + ex.getMessage());
                   System.err.println("+================================+");
              }**/ catch (SAXException ex) {
                   System.err.println("+================================+");
                   System.err.println("|          *SAX Error*           |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("+================================+");
              /*}} catch (SAXNotRecognizedException  ex) {
                   System.err.println(" no SAX");*/
              } catch (ParserConfigurationException ex) {
                   System.err.println(" ???");
               } catch (IOException ex) {
                   System.err.println("+================================+");
                   System.err.println("|           *XML Error*          |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
    private static class JFileChooserrv {
         JFileChooserrv(JFrame f, boolean vverabreiten) {
              String openfile;
              String verror;
              boolean validate = true;
              final JFrame frame = f;
              String vFilename = "Z:\\Boorberg\\parsen_vista\\daten";
              //String vFilename = "C:\\";
              File vFile = new File(vFilename);
              final JFileChooser chooser = new JFileChooser(vFile);
              JFileFilter filter = new JFileFilter();
              filter.addType("xml");
              filter.addType("sgml");
              filter.addType("html");
              filter.addType("java");
              filter.setDescription("strukturfiles");
              chooser.addChoosableFileFilter(filter);
              boolean vjeas = true;
              chooser.setMultiSelectionEnabled(vjeas);
              int returnVal = chooser.showOpenDialog(frame);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                   //Array  filearry[] = chooser.getSelectedFiles();
                   //if (vFile = chooser.getSelectedFiles()) {
                   //File  file[] = chooser.getSelectedFiles();
                   File  vfile[] = chooser.getSelectedFiles();
                   //String openfile = new String();
                   int vlenght = vfile.length;
                   if (vlenght>1) {
                        int x=0;
                        while (x< vlenght) {
                                  parse(vfile[x], validate);
                                  x = x +1;
                   if (vlenght<=1) {
                        File v2file = chooser.getSelectedFile();
                             parse(v2file, validate);
              } else {
                   System.out.println("You did not choose a filesystem           object.");
         System.exit(0);
    private static class JFileFilter extends javax.swing.filechooser.FileFilter {
         protected String description, vnew;
         protected ArrayList<String> exts = new ArrayList<String>();
         protected boolean vtrue;
         public void addType(String s) {
              exts.add(s);
         /** Return true if the given file is accepted by this filter. */
         public boolean accept(File f) {
              // Little trick: if you don't do this, only directory names
              // ending in one of the extentions appear in the window.
              if (f.isDirectory()) {
                   return true;
              } else if (f.isFile()) {
                   Iterator it = exts.iterator();
                   while (it.hasNext()) {
                        if (f.getName().endsWith((String)it.next()))
                             return true;
              // A file that didn't match, or a weirdo (e.g. UNIX device file?).
              return false;
         /** Set the printable description of this filter. */
         public void setDescription(String s) {
              description = s;
         /** Return the printable description of this filter. */
         public String getDescription() {
              return description;
    private static class MyErrorHandler implements ErrorHandler {
            // Error handler output goes here
            private PrintStream out;
            MyErrorHandler(PrintStream out) {
                this.out = out;
             * Returns a string describing parse exception details
            private String getParseExceptionInfo(SAXParseException spe) {
                String systemId = spe.getSystemId();
                if (systemId == null) {
                    systemId = "null";
                String info = "URI=" + systemId +
                    " Line=" + spe.getLineNumber() +
                    ": " + spe.getMessage();
                return info;
            // The following methods are standard SAX ErrorHandler methods.
            // See SAX documentation for more info.
            public void warning(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                //out.println("Warning: " + getParseExceptionInfo(spe));
            public void error(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
            public void fatalError(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Fatal Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
         public static void main(String[] av) {
              JFrame vframe = new JFrame("chose files to pars");
              boolean vverabreiten = true;
              boolean validate = true;
              JFileChooserrv vdateienwaehlen = new JFileChooserrv(vframe, vverabreiten);
    }The Stack Trace i posted in the last Message. But i couldn't read it, i am not a programmer.

  • XML parsers in JAVA

    Hi all,
    I need to parse XML files in JAVA. Is there any specific package in java for XML parsing?

    Example for using DOM :
    import java.io.File;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    // using DOM
    public class ParseXML_Dom {
        public static void main(String[] args) {
            File file = new File("test.xml");
            try {
                DocumentBuilder builder =
                        DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document doc = builder.parse(file);
                NodeList nodes = doc.getElementsByTagName("topic");
                for (int i = 0; i < nodes.getLength(); i++) {
                    Element element = (Element) nodes.item(i);
                    NodeList title = element.getElementsByTagName("title");
                    Element line = (Element) title.item(0);
                    System.out.println("Title: " + getCharacterDataFromElement(line));
                    NodeList url = element.getElementsByTagName("url");
                    line = (Element) url.item(0);
                    System.out.println("Url: " + getCharacterDataFromElement(line));
            } catch (Exception e) {
                e.printStackTrace();
         The file "text.xml" might contain this :
    <?xml version="1.0"?>
    <howto>
      <topic>
          <title>Searching</title>
          <url>http://www.google.com</url>
      </topic>
        <topic>
          <title>Masturbation</title>
          <url>http://www.jackinworld.com</url>
      </topic>
          <topic>
            <title>Shopping</title>
            <url>http://www.amazon.com</url>
      </topic>
          <topic>
            <title>Sound</title>
            <url>http://www.dailywav.com</url>
      </topic>
    </howto>
        public static String getCharacterDataFromElement(Element e) {
            Node child = e.getFirstChild();
            if (child instanceof CharacterData) {
                CharacterData cd = (CharacterData) child;
                return cd.getData();
            return "?";
    }

Maybe you are looking for