ok, I'try to clarify more disctinctly what I need. xml file example: <?xml version="1.0" encoding="ISO-8859-1"?> <subscribers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='subs.xsd'> <subscriber> <name>Name1</name> <age>34</age> </subscriber> <subscriber> <name>Name2</name> </subscriber> </subscribers>
this xml is parsed using the following xml schema and xsl stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> <xs:element name="subscribers"> <xs:complexType> <xs:sequence> <xs:element ref="subscriber" minOccurs='1' maxOccurs='unbounded'/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="subscriber"> <xs:complexType> <xs:sequence> <xs:element ref="name" minOccurs="1" maxOccurs="1" /> <xs:element ref="age" minOccurs="1" maxOccurs="1" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="name" type="xs:string" /> <xs:element name="age" type="xs:integer" /> </xs:schema> <?xml version="1.0" encoding="ISO-8859-1" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="subscribers"> <subscribersT><xsl:apply-templates select="subscriber" /></subscribersT> </xsl:template> <xsl:template match="subscriber"> <subscriberT><xsl:apply-templates select="name|age"/></subscriberT> </xsl:template> <xsl:template match="name"> <nameT><xsl:apply-templates select="text()"/></nameT> </xsl:template> <xsl:template match="age"> <ageT><xsl:apply-templates select="text()"/></ageT> </xsl:template> </xsl:stylesheet> The java code is placed below: TransformerFactory tFactory = TransformerFactory.newInstance(); SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory); saxTFactory.setAttribute ("http://xml.apache.org/xalan/features/incremental", Boolean.TRUE); TemplatesHandler templatesHandler = saxTFactory.newTemplatesHandler(); XMLReader parser = XMLReaderFactory.createXMLReader(org.apache.xerces.parsers.SAXParser); parser.setContentHandler(templatesHandler); parser.parse(xslFile); Templates templates = templatesHandler.getTemplates(); TransformerHandler handler = saxTFactory.newTransformerHandler(templates); parser.setContentHandler(new MyContentHandler(handler)); parser.setErrorHandler(myHandler); parser.setFeature("http://xml.org/sax/features/namespaces", true); parser.setFeature("http://xml.org/sax/features/validation", true); parser.setFeature( "http://apache.org/xml/features/validation/schema", true); parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error ", false); SerializerToXML serializer = new SerializerToXML(); serializer.setOutputStream(System.out); Result result = new SAXResult(serializer.asContentHandler()); handler.setResult(result); parser.parse(xml InputSource); MyContentHandler class implements ContentHandler and wraps TransformerHandler (I only want to display info when the element starts and ends). As the result of transformation I would like to get the following structure: <subscribersT> <subscriberT> <name>Name1</name> <age>34</age> </subscriberT> </subscribersT> I do NOT want to get additionally: <subscriberT> <name>Name2</name> </subscriberT> as now, because this fragment is not valid with xml schema ( <xs:element ref="name" minOccurs="1" maxOccurs="1" />) The xml file can be very big file, I can NOT stop parsing and transforming. Can I do that using xalan ? Sorry for long listning :-) and thanks, Pawel -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, January 07, 2002 3:30 PM To: [EMAIL PROTECTED] Subject: Re: filter transformer's input I'm a little confused - it might help to have an abbreviated code sample showing how you're invoking the transformer. Xalan doesn't know anything implicitly about schema validation, so there's no magic bullet for this case. If you're already using an ErrorHandler, then why isn't that just reporting the error as you prefer, re-throwing the exception, which should cause the transformer to stop? Oh, wait: are you saying that you want to replace just this one bit of data (which happens to violate a schema constraint, which caused your ErrorHandler's error() to fire, where you're then ignoring the error and asking the parser and transformer to continue) with a new bit of data and hoping the parse & transform will continue normally? I'm not sure that there's a generic way to replace just one value element in the middle of a parse like this. - Shane ---- you "Pawel Bieryt" <[EMAIL PROTECTED]> wrote ---- hi all, I use SAX to SAX transformation. I have to parse my xml file with schema validation and transform using the XSL stylesheet to produce SAXResult as output of transformation. Using the latest xalan(xalan-j_2_2_D10) and xerces (xerces-2_0_0_beta4) I can do that almost simultaneously (I mean I can start the transformation during the parsing) Let's assume I have the occurrence constraint 'minOccurs' in my schema file. So if my xml file violates this constraint the SAX parser raises the exception which I can handle by implementing ErrorHandler interface (the method 'error' in this case). The SAX parser continuos parsing... Such processed data I have to pass to some other application. And the problem: I can NOT pass the data which violate the the constraints. So can I somehow filter the input for the transformer ? Can I somehow force the transformer not to process the data which violate the constraints? Thanks for your help or suggestions in advance.
