"Unique Particle Attribution" error when validating XSD using SAX apache xerces

Hi,

I think because I am creating a circular reference, as I have allowed an option element to contain an options element which must contain an option element in the XDS below, I am getting a

'os-nonambig: WC[##any] and "http://....":options (or lements from their substitution groups) violate "Unique Particle Attribution".  During validation against this schema, ambiguity would be created for those two particles.'

error when validating using SAX (Java) / apache xerces.  I have experimented with using another namespace "ab" as you can see below, but this hasn't worked, I get the same error.  I want the ability for an option to contain options, how would I go about this?

Cheers, Steve
LVL 5
steve_bagnallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
steve_bagnallAuthor Commented:
sorry ...

<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://www.churchillchina.com/gapanalysis"
            xmlns="http://www.churchillchina.com/gapanalysis"
            xmlns:ab="http://www.churchillchina.com/gapanalysis"
            elementFormDefault="qualified" attributeFormDefault="unqualified">

     <xsd:element name="choices" type="choicesType" />
           
     <xsd:complexType name="choicesType" mixed="true">
                        <xsd:complexContent>
                                    <xsd:extension base="xsd:anyType">
                                          <xsd:sequence>
                <xsd:element name="choice" type="choiceType" minOccurs="1" maxOccurs="unbounded" />
                                          </xsd:sequence>
                                    </xsd:extension>
          </xsd:complexContent>
     </xsd:complexType>

     <xsd:complexType name="choiceType" mixed="true">
          <xsd:complexContent>
                                          <xsd:extension base="xsd:anyType">
                  <xsd:sequence>
                    <xsd:element name="options" type="ab:optionsType" minOccurs="1" maxOccurs="unbounded" />
                                              </xsd:sequence>
                  <xsd:attribute name="class" type="xsd:string" use="required" />
                  <xsd:attribute name="function" type="xsd:string" use="required" />
                                          </xsd:extension>
          </xsd:complexContent>
     </xsd:complexType>

     <xsd:complexType name="optionsType" mixed="true">
          <xsd:complexContent>
               <xsd:extension base="xsd:anyType">
                 <xsd:sequence>
                   <xsd:element name="option" type="ab:optionType" minOccurs="1" maxOccurs="unbounded" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" use="required" />
               </xsd:extension>
          </xsd:complexContent>
     </xsd:complexType>

     <xsd:complexType name="optionType" mixed="true">
          <xsd:complexContent>
               <xsd:extension base="xsd:anyType">
                  <xsd:sequence>
                    <xsd:element name="options" type="optionsType" minOccurs="0" maxOccurs="unbounded" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" use="required" />
               </xsd:extension>
          </xsd:complexContent>
     </xsd:complexType>

</xsd:schema>
0
 
aozarovCommented:
Hi steve_bagnall :-)
I will have a look at it in 2-3 hours  (unless someone else solved it by then)
0
 
aozarovCommented:
Ok,
No I don't think it has to do with "I am creating a circular reference" as an element can contain an element of the type of its parent.
Try this schema instead of yours (removed the uneeded xsd:anyType complexContent/extension)
It is working for me fine with the XML posted in your previous question.

<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://www.churchillchina.com/gapanalysis"
          xmlns="http://www.churchillchina.com/gapanalysis"
          elementFormDefault="qualified" attributeFormDefault="unqualified">

     <xsd:element name="choices" type="choicesType" />
         
     <xsd:complexType name="choicesType" mixed="true">
           <xsd:sequence>
                <xsd:element name="choice" type="choiceType" minOccurs="1" maxOccurs="unbounded" />
             </xsd:sequence>
     </xsd:complexType>

     <xsd:complexType name="choiceType" mixed="true">
           <xsd:sequence>
                    <xsd:element name="options" type="optionsType" minOccurs="1" maxOccurs="unbounded" />
             </xsd:sequence>
             <xsd:attribute name="class" type="xsd:string" use="required" />
             <xsd:attribute name="function" type="xsd:string" use="required" />
     </xsd:complexType>

     <xsd:complexType name="optionsType" mixed="true">
           <xsd:sequence>
                   <xsd:element name="option" type="optionType" minOccurs="1" maxOccurs="unbounded" />
             </xsd:sequence>
             <xsd:attribute name="name" type="xsd:string" use="required" />
     </xsd:complexType>

     <xsd:complexType name="optionType" mixed="true">
           <xsd:sequence>
                    <xsd:element name="options" type="optionsType" minOccurs="0" maxOccurs="unbounded" />
             </xsd:sequence>
             <xsd:attribute name="name" type="xsd:string" use="required" />
     </xsd:complexType>

</xsd:schema>
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
steve_bagnallAuthor Commented:
Hi,

Thanks for that.  The previous error goes when I use your xsd, but I now get a java.lang.IllegalStateException, which is ultimately raised by the following line:

document = builder.parse(new File(argv[0]));

Cheers,
Steve
0
 
aozarovCommented:
Can you provide the stackTrace?
If your input xml is different from the one posted in the previous thread then post it as well (because I used your code(with my fix) and your xml from the previous thread and  managed to build the document succesfuly).
0
 
steve_bagnallAuthor Commented:
Any idea how to get the stack trace out of the DOS shell?  In the meantime, here's the XML, I think it's the same :


<?xml version='1.0' encoding='utf-8'?>

<choices
     xmlns="http://www.churchillchina.com/gapanalysis"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.churchillchina.com/gapanalysis test.xsd">
         
     <choice class="retail" function="search">
          <options name="type">
               <option name="MASS MARKETS">
                    <options name="category">
                         <option name="DISCOUNT" />
                         <option name="VOLUME" />
                         <option name="OTHERS" />
                    </options>
               </option>
               <option name="MIDDLE MARKETS">
                    <options name="category">
                         <option name="MIDDLE MARKETS" />
                    </options>
               </option>
          </options>
     </choice>
     
     <choice class="retail" function="data">
          <options name="type">
               <option name="MASS MARKETS">
                    <options name="cat">
                         <option name="DISCOUNT" />
                         <option name="VOLUME" />
                         <option name="OTHERS" />
                    </options>
               </option>
               <option name="MIDDLE MARKETS">
                    <options name="category">
                         <option name="MIDDLE MARKETS" />
                    </options>
               </option>
          </options>
     </choice>

     <choice class="product" function="search">
          <options name="product group">
               
               <option name="MUGS">
                    <options name="body type">
                         <option name="SPECIFIC" />
                         <option name="BONE CHINA" />
                         <option name="PORCELAIN" />
                         <option name="STONEWARE" />
                         <option name="EARTHENWARE" />
                         <option name="FINE CHINA" />
                         <option name="GLASS" />
                         <option name="OTHER" />
                    </options>
                    <options name="size">
                         <option name="7 OZ OR LESS" />
                         <option name="8 OZ" />
                         <option name="9 OZ" />
                         <option name="10 OZ" />
                         <option name="12 OZ" />
                         <option name="14 OZ" />
                         <option name="16 OZ" />
                         <option name="18 OZ" />
                         <option name="20 OZ" />
                         <option name="20 OZ +" />
                    </options>
                    <options name="shape">
                         <option name="TRADITIONAL M/C MADE" />
                         <option name="TRADITIONAL CAST" />
                         <option name="TRADITIONAL OTHER" />
                         <option name="MODERN M/C MADE" />
                         <option name="MODERN CAST" />
                         <option name="MODERN OTHER" />
                    </options>
                    <options name="design category">
                         <option name="CLASSIC">
                              <options name="design">
                                   <option name="ART DECO" />
                                   <option name="NOUVEAU" />
                                   <option name="WILLIAM MORRIS" />
                                   <option name="TOILE" />
                                   <option name="PAISLEY" />
                              </options>
                         </option>
                         <option name="MODERN CLASSIC" />
                         <option name="TRADITIONAL">
                              <options name="design">
                                   <option name="FRUIT" />
                                   <option name="FLORAL" />
                                   <option name="THEMED (NAUTICAL/COCKEREL)" />
                                   <option name="COUNTRY" />    
                              </options>
                         </option>
                         <option name="CONTEMPERARY">
                              <options name="design">
                                   <option name="FLORAL" />
                                   <option name="GEOMETRIC" />    
                              </options>
                         </option>
                         <option name="NATURAL (RETREAT)">
                              <options name="design">
                                   <option name="ORGANIC" />
                              </options>
                         </option>
                         <option name="URBAN">
                              <options name="design">
                                   <option name="LOFT" />
                                   <option name="RETRO" />
                              </options>
                         </option>
                         <option name="GLOBAL VILLAGE (FUSION)">
                              <options name="design">
                                   <option name="ETHNIC" />
                                   <option name="MORROCO" />
                                   <option name="INDIAN" />
                                   <option name="JAPANESE" />
                              </options>
                         </option>
                         <option name="MONO">
                              <options name="design">
                                   <option name="BLACK" />
                                   <option name="RED" />
                              </options>
                         </option>
                         <option name="BOUDOIR/ROMANCE" />
                         <option name="FUN/FUNKY">
                              <options name="design">
                                   <option name="CATS/DOGS" />
                                   <option name="FARMYARD (PIG/COW/SHEEP)" />
                                   <option name="CHARACTER" />
                              </options>
                         </option>
                         <option name="SIMPLICITY (MINIMALIST)">
                              <options name="design">
                                   <option name="WHITE" />
                              </options>
                         </option>
                         <option name="SEASONS">
                              <options name="design">
                                   <option name="EASTER" />
                                   <option name="CHRISTMAS" />
                                   <option name="HALIOWEEN" />
                                   <option name="BACK TO SCHOOL" />
                              </options>
                         </option>
                         <option name="COLOUR">
                              <options name="design">
                                   <option name="THEMES" />
                              </options>
                         </option>
                    </options>
                   
                    <options name="brand">
                         <option name="DUNOON" />
                         <option name="HUDSON &amp; MIDDLETON" />
                         <option name="ROY KIRKHAM" />
                         <option name="TTC" />
                         <option name="GLENEAGLES" />
                         <option name="RAYWARE" />
                         <option name="RANSAAT" />
                         <option name="PREMIER HOUSEWARES" />
                         <option name="EMS (TRADEWINDS, WATERSIDE)" />
                         <option name="JUST MUGS" />
                         <option name="TAMS" />
                    </options>
                   
                    <options name="packaging">
                         <option name="LOOSE" />
                         <option name="INDIVIDUAL BOX" />
                         <option name="MULTI PACK 2" />
                         <option name="MULTI PACK 3" />
                         <option name="MULTI PACK 4" />
                         <option name="MULTI PACK 6" />
                         <option name="MULTI PACK 8" />
                         <option name="MULTI PACK 12" />
                         <option name="OTHER" />
                    </options>
               </option>
          </options>
     </choice>

     <choice class="product" function="data">
          <options name="productgroup">

               <option name="MUGS">
                    <options name="body type">
                         <option name="SPECIFIC" />
                         <option name="BONE CHINA" />
                         <option name="PORCELAIN" />
                         <option name="STONEWARE" />
                         <option name="EARTHENWARE" />
                         <option name="FINE CHINA" />
                         <option name="GLASS" />
                         <option name="OTHER" />
                    </options>
                    <options name="size">
                         <option name="7 OZ OR LESS" />
                         <option name="8 OZ" />
                         <option name="9 OZ" />
                         <option name="10 OZ" />
                         <option name="12 OZ" />
                         <option name="14 OZ" />
                         <option name="16 OZ" />
                         <option name="18 OZ" />
                         <option name="20 OZ" />
                         <option name="20 OZ +" />
                    </options>
                    <options name="shape">
                         <option name="TRADITIONAL M/C MADE" />
                         <option name="TRADITIONAL CAST" />
                         <option name="TRADITIONAL OTHER" />
                         <option name="MODERN M/C MADE" />
                         <option name="MODERN CAST" />
                         <option name="MODERN OTHER" />
                    </options>
                    <options name="design category">
                         <option name="CLASSIC">
                              <options name="design">
                                   <option name="ART DECO" />
                                   <option name="NOUVEAU" />
                                   <option name="WILLIAM MORRIS" />
                                   <option name="TOILE" />
                                   <option name="PAISLEY" />
                              </options>
                         </option>
                         <option name="MODERN CLASSIC" />
                         <option name="TRADITIONAL">
                              <options name="design">
                                   <option name="FRUIT" />
                                   <option name="FLORAL" />
                                   <option name="THEMED (NAUTICAL/COCKEREL)" />
                                   <option name="COUNTRY" />    
                              </options>
                         </option>
                         <option name="CONTEMPERARY">
                              <options name="design">
                                   <option name="FLORAL" />
                                   <option name="GEOMETRIC" />    
                              </options>
                         </option>
                         <option name="NATURAL (RETREAT)">
                              <options name="design">
                                   <option name="ORGANIC" />
                              </options>
                         </option>
                         <option name="URBAN">
                              <options name="design">
                                   <option name="LOFT" />
                                   <option name="RETRO" />
                              </options>
                         </option>
                         <option name="GLOBAL VILLAGE (FUSION)">
                              <options name="design">
                                   <option name="ETHNIC" />
                                   <option name="MORROCO" />
                                   <option name="INDIAN" />
                                   <option name="JAPANESE" />
                              </options>
                         </option>
                         <option name="MONO">
                              <options name="design">
                                   <option name="BLACK" />
                                   <option name="RED" />
                              </options>
                         </option>
                         <option name="BOUDOIR/ROMANCE" />
                         <option name="FUN/FUNKY">
                              <options name="design">
                                   <option name="CATS/DOGS" />
                                   <option name="FARMYARD (PIG/COW/SHEEP)" />
                                   <option name="CHARACTER" />
                              </options>
                         </option>
                         <option name="SIMPLICITY (MINIMALIST)">
                              <options name="design">
                                   <option name="WHITE" />
                              </options>
                         </option>
                         <option name="SEASONS">
                              <options name="design">
                                   <option name="EASTER" />
                                   <option name="CHRISTMAS" />
                                   <option name="HALIOWEEN" />
                                   <option name="BACK TO SCHOOL" />
                              </options>
                         </option>
                         <option name="COLOUR">
                              <options name="design">
                                   <option name="THEMES" />
                              </options>
                         </option>
                    </options>

                    <options name="brand">
                         <option name="DUNOON" />
                         <option name="HUDSON &amp; MIDDLETON" />
                         <option name="ROY KIRKHAM" />
                         <option name="TTC" />
                         <option name="GLENEAGLES" />
                         <option name="RAYWARE" />
                         <option name="RANSAAT" />
                         <option name="PREMIER HOUSEWARES" />
                         <option name="EMS (TRADEWINDS, WATERSIDE)" />
                         <option name="JUST MUGS" />
                         <option name="TAMS" />
                    </options>

                    <options name="packaging">
                         <option name="LOOSE" />
                         <option name="INDIVIDUAL BOX" />
                         <option name="MULTI PACK 2" />
                         <option name="MULTI PACK 3" />
                         <option name="MULTI PACK 4" />
                         <option name="MULTI PACK 6" />
                         <option name="MULTI PACK 8" />
                         <option name="MULTI PACK 12" />
                         <option name="OTHER" />
                    </options>
               </option>

          </options>
     </choice>
                   
     <choice class="prodinret" function="search">
          <options name="acorn">
               <option name="A: THRIVING" />
               <option name="B: EXPANDING" />
               <option name="C: RISING" />
               <option name="D: SETTLING" />
               <option name="E: ASPIRING" />
               <option name="F: STRIVING" />
          </options>
         
          <options name="price">
               <option name="&lt;See PriceRanges.java&gt;" />
          </options>
     </choice>
     
     <choice class="prodinret" function="data">
          <options name="acorn">
               <option name="A: THRIVING" />
               <option name="B: EXPANDING" />
               <option name="C: RISING" />
               <option name="D: SETTLING" />
               <option name="E: ASPIRING" />
               <option name="F: STRIVING" />
          </options>

          <options name="price">
               <option name="&lt;See PriceRanges.java&gt;" />
          </options>
     </choice>
     
</choices>
0
 
aozarovCommented:
>Any idea how to get the stack trace out of the DOS shell?  
in your program where you catch the Exception generated by "document = builder.parse(new File(argv[0]));" add ex.printStackTrace();
e.g
try
{
....
document = builder.parse(new File(argv[0]));
...
}
catch (Exception ex)
{
ex.printStackTrace();
}
0
 
steve_bagnallAuthor Commented:
Hi,  Yeah I have that - I just can't copy it from within the DOS shell.. it is quite long.  I've tried >>err.txt etc. but no joy.  Seems a stupid thing to struggle on I know but....
0
 
steve_bagnallAuthor Commented:
Anyway we seem to work at opposite ends of the day .. so I'll see you tomorrow!
0
 
aozarovCommented:
The files are identical and I can parse it (build Dom document) without any problem.
Once you provide the stack trace I can take it further as I am not sure it is directly related to the parsing.
Also together with the stack trace paste here the java file that creates the Dom Document.
0
 
steve_bagnallAuthor Commented:
Hi,

Heres the stack trace followed by the Java file, thanks ...


STACK TRACE ================================

java.lang.IllegalStateException
      at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.checkState(ValidatorHandlerImpl.java:411)
      at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl$3.getElementTypeInfo(ValidatorHandlerImpl.java:441)
      at com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.elementAug(JAXPValidatorComponent.java:299)
      at com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent$SAX2XNI.endElement(JAXPValidatorComponent.java:291)
      at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
      at com.sun.org.apache.xerces.internal.jaxp.validation.XNI2SAXEx.endElement(XNI2SAXEx.java:108)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:818)
      at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:339)
      at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.endElement(XNI2SAX.java:163)
      at com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent.endElement(JAXPValidatorComponent.java:206)
      at com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent.emptyElement(JAXPValidatorComponent.java:211)
      at com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler.emptyElement(XIncludeHandler.java:755)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:316)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1693)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:248)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
      at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:169)
      at com.churchillchina.utils.XMLDOM.main(XMLDOM.java:164)



JAVA FILE =======================================

package com.churchillchina.utils;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import java.io.File;
import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.DOMException;

// GUI components and layouts
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;

import javax.swing.JSplitPane;
import javax.swing.JEditorPane;

// GUI support classes
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;


import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.io.File;





public class XMLDOM extends JPanel {

      static Document document;


      static final int windowHeight = 460;
      static final int leftWidth = 300;
      static final int rightWidth = 340;
    static final int windowWidth = leftWidth + rightWidth;

    private static PrintWriter m_ErrLog;


      public XMLDOM() {


            // Set up the tree
            JTree tree = new JTree();

            // Build left-side view
            JScrollPane treeView = new JScrollPane(tree);
            treeView.setPreferredSize(new Dimension( leftWidth, windowHeight ));

            // Build right-side view
            JEditorPane htmlPane = new JEditorPane("text/html","");
            htmlPane.setEditable(false);
            JScrollPane htmlView = new JScrollPane(htmlPane);
            htmlView.setPreferredSize(new Dimension( rightWidth, windowHeight ));


            // Build split-pane view
            JSplitPane splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, treeView, htmlView );
            splitPane.setContinuousLayout( true );
            splitPane.setDividerLocation( leftWidth );
            splitPane.setPreferredSize(
            new Dimension( windowWidth + 10, windowHeight+10 ));

            // Add GUI components
            this.setLayout(new BorderLayout());
            this.add("Center", splitPane );





      } // Constructor


      public static void main(String  [] argv) {



            System.out.println("ABOUT TO CREAT ERR.TXT");
            try {
                  // set up error log
                  m_ErrLog = new PrintWriter(new File("err.txt"));
                  System.out.println("CREATED ERR.TXT");
            } catch (java.io.FileNotFoundException ioe) {
                  ioe.printStackTrace();
            }


            if (argv.length != 1) {
                  System.err.println("Usage: java XMLDOM filename");
                  System.exit(1);
            }

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

            // set validation awareness

            // factory.setValidating(true);
            factory.setNamespaceAware(true);


            //factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");


            try {
                  javax.xml.validation.Schema schema = javax.xml.validation.SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema").newSchema(
                        new File("com/churchillchina/utils/test.xsd"));
                  factory.setSchema(schema);


                  DocumentBuilder builder = factory.newDocumentBuilder();

                  /* complicated exception stuff - maybe delete later! */
                  builder.setErrorHandler(
                        new org.xml.sax.ErrorHandler() {

                              // ignore fatal errors (an exception is guaranteed)
                              public void fatalError(SAXParseException exception) throws SAXException {
                              }

                              // treat validation errors as fatal
                              public void error(SAXParseException e) throws SAXParseException {
                                    throw e;
                              }

                              // dump warnings too
                              public void warning(SAXParseException err) throws SAXParseException {
                                    System.out.println("** Warning" + ", line " + err.getLineNumber()
                                    + ", uri " + err.getSystemId());
                                    System.out.println("   " + err.getMessage());
                              }
                          }
                  );

                   /* end of exception bit */


                  /*
                  SAXParserFactory saxFactory = SAXParserFactory.newInstance();
                  SAXParser saxParser = saxFactory.newSAXParser();
                  org.xml.sax.XMLReader xmlReader = saxParser.getXMLReader();
                  xmlReader.setFeature("http://apache.org/xml/features/validation/schema", true);
                  */

                  document = builder.parse(new File(argv[0]));

                  makeFrame();


            } catch (IllegalStateException ise) {

                  System.out.println("PRINTING 0");
                  m_ErrLog.print(getStackTrace(ise));
                  m_ErrLog.flush();
                  m_ErrLog.close();

            } catch (SAXException e) {
                  // Error generated during parsing

                  System.out.println("PRINTING 1");
                  m_ErrLog.print(getStackTrace(e));

                  Exception x = e;
                  if (e.getException() != null) {
                        x = e.getException();
                  }
                  x.printStackTrace();
                  System.out.println(x.getMessage());

            } catch (ParserConfigurationException e) {

                  System.out.println("PRINTING 2");
                  m_ErrLog.print(getStackTrace(e));

                  // Parser with specified options can't be built
                  e.printStackTrace();
                  System.out.println(e.getMessage());
            } catch (IOException e) {

                  System.out.println("PRINTING 3");
                  m_ErrLog.print(getStackTrace(e));
                  // I/O Error
                  e.printStackTrace();
                  System.out.println(e.getMessage());
            }


      } // end of main

      public static void makeFrame() {
          // Set up a GUI framework
          JFrame frame = new JFrame("DOM Test");
          frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
          });

          // Set up the tree, the views, and display it all
          final XMLDOM domPanel = new XMLDOM();
          frame.getContentPane().add("Center", domPanel );
          frame.pack();
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          int w = windowWidth + 10;
          int h = windowHeight + 10;
          frame.setLocation(screenSize.width/3 - w/2, screenSize.height/2 - h/2);
          frame.setSize(w, h);
          frame.setVisible(true);
      } // makeFrame



      public static String getStackTrace(Throwable t)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        t.printStackTrace(pw);
        pw.flush();
        sw.flush();
        return sw.toString();
    }

}
0
 
aozarovCommented:
I am not sure what to tell you as your program runs fine for me (with the xsd I provided and the xml and XMLDOM java file you pasted here).
What version of java 1.5 are you using? what platform are you running it on?
This is my java version:
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)
On the web some suggest a JVM bug is there a way for you to check your progarm on a machine with differen (more recent) 1.5 JVM?
0
 
steve_bagnallAuthor Commented:
I seem to have the latest build available on the web site.  Since you got rid of the particle error, think I'll close this question down and re-open in the Java forums.  

Thanks for your help, Steve.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.