Michael

Thank you for your reply. I thought that was the case and given that it is
part of the Soap body, I knew it just needed to be well-formed XML. Yes that
should be the namespace for that element. However, I have no way of
enforcing the association between the elements and that namespace. Any
suggestions on how can I enforce this? At one point, I was parsing the XML,
reading all the namespaces and if my namespace was not one in the list, I
threw an exception. However, that still does not work because if you declare
it in the SOAP envelope, the parser does not complain. Any suggestions would
be greatly appreciated as this is a "bug" in my system.

Thanks
brenda 

Michael Glavassevich-3 wrote:
> 
> 
> Hi Brenda,
> 
> The element names in your document must match the elements declared in
> your
> schema. Their namespace is part of the name. The default namespace is
> terminology for the namespace binding for elements (and QNames in content)
> with no prefix. Also, the prefixes you declare in the schema have no
> bearing on their mapping in the instance document. You haven't declared
> the
> default namespace in your instance document, so the "getReference" element
> has no namespace. It seems like its namespace should be "?
> http://service.arm.hud.gov/";. Because the content of "soapenv:Body" is
> laxly validated you won't get an error for that..
> 
> Thanks.
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: [email protected]
> E-mail: [email protected]
> 
> Brenda Coulson <[email protected]> wrote on 10/20/2009 01:44:58 PM:
> 
>>
>> Ok - I have made progess!! Based on a post I saw in the forums, I
> switched
>> the way I set the schemas and that has improved things tremendously. I am
> no
>> longer getting that wacky error about OpenDNS. However, the parser is
> still
>> not validating my XML file as I would expect it to.
>>
>> Here is the XML file I am trying to validate:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";>
>>    <soapenv:Header/>
>>    <soapenv:Body>
>>       <getReference>
>>      <agcHcsId>80000</agcHcsId>
>>       </getReference>
>>    </soapenv:Body>
>> </soapenv:Envelope>
>>
>> It is missing a required child element referenceId of getReference but
> the
>> parser does not complain. I know that I do not specify the namespace in
> the
>> XML file but since it is specified to the Parser, I would have thought it
>> would use it to validate. Is this a problem of it assuming that my XML is
> in
>> the default namespace and therefore not using the XSD I specify? If so,
> how
>> can I tell it to use my schema for both the target namespace and the
> default
>> namespace in the event that someone submits an XML similar to above?
>>
>> Here is my modified source code:
>>
>> String soapSchemaVersion = null;
>> if(soapVersion == 1.1) {
>>    soapSchemaVersion = "gov/hud/arm/xsd/soap-envelope-1.1.xsd";
>> } else {
>>    soapSchemaVersion = "gov/hud/arm/xsd/soap-envelope-1.2.xsd";
>> }
>> System.setProperty("javax.xml.validation.SchemaFactory:http://www.
>> w3.org/2001/XMLSchema",
>> "org.apache.xerces.jaxp.validation.XMLSchemaFactory");
>> System.setProperty("jaxp.debug", "1");
>>
>> SAXParserFactory parserFactory = SAXParserFactory.newInstance();
>> parserFactory.setNamespaceAware(true);
>> parserFactory.setValidating(false);
>> parserFactory.setFeature
> ("http://apache.org/xml/features/validation/schema";,
>> true);
>> parserFactory.setFeature("http://xml.org/sax/features/validation";, true);
>>
>> SAXParser parser = parserFactory.newSAXParser();
>> // set up the schema
>> Object schemas = ARM_NAMESPACE + " " + new
>> ClassPathResource(xsdResource).getURI() + " " +
>>     "http://schemas.xmlsoap.org/soap/envelope/"; + " " +
>>     new ClassPathResource(soapSchemaVersion).getURI();
>> parser.setProperty("http://apache.
>> org/xml/properties/schema/external-schemaLocation",
>> schemas);
>> XMLReader reader = parser.getXMLReader();
>>
>> ArmHandler handler = new ArmHandler();
>> reader.setErrorHandler(handler);
>> reader.parse(new InputSource(payload));
>> return handler.getExceptions();
>>
>>
>> Brenda Coulson wrote:
>> >
>> > One more thing - I am attaching the two "external" schemas - xmime and
>> > xop-include.
>> >
>> > Brenda Coulson wrote:
>> >>
>> >> Michael
>> >>
>> >> Thank you for your reply. Unfortunately there is no "OpenDNS" showing
> up
>> >> anywhere in my XML or source code files. It is quite bizarre. The fact
>> >> that I can get the XML to validate with the XMLValidator from Spring
>> >> tells me that the XML is valid and that I can use the remote locations
> of
>> >> xmime and xop-include schemas and it works. I have copied these
> version
>> >> locally so that I know they have the same content.
>> >>
>> >> I am attaching a copy of the stack trace that I receive. I could not
> find
>> >> information about the URL in the SAXParseException message- that would
> be
>> >> very useful if I could get that information.
>> >>
>> >> Regards
>> >> Brenda
>> >>
>> >> Michael Glavassevich-3 wrote:
>> >>>
>> >>>
>> >>> Hi Brenda,
>> >>>
>> >>> The error message you're getting complains about "OpenDNS" appearing
> in
>> >>> some document yet doesn't appear in any of the data you've shown.
> Such
>> >>> text
>> >>> doesn't just appear magically. There's some other document involved
> here
>> >>> that you haven't posted. It would help if you could make a connection
>> >>> between the error message you're getting and the input that you're
>> >>> feeding
>> >>> to Xerces and may also be useful to show us the stack trace rather
> than
>> >>> just mentioning that there was one. There should be information about
>> >>> the
>> >>> document's location (URL) in the SAXParseException in case you're not
>> >>> sure
>> >>> where to look for it.
>> >>>
>> >>> Thanks.
>> >>>
>> >>> Michael Glavassevich
>> >>> XML Parser Development
>> >>> IBM Toronto Lab
>> >>> E-mail: [email protected]
>> >>> E-mail: [email protected]
>> >>>
>> >>> Brenda Coulson <[email protected]> wrote on 10/19/2009 12:10:54 PM:
>> >>>
>> >>>> Ok - I have been struggling with this for over two weeks now and am
>> >>>> about to pull out my hair. I have scrubbed discussion groups,
>> >>>> websites for help but alas I come up with nothing. I am trying to
>> >>>> validate an XML file against the XSD schema and running into some
>> >>>> problems. The XML I would like to validate is the payload of a web
>> >>>> service SOAP message. I am using the SAXParserFactory to generate my
>> >>>> parser and I am doing the following in my code to set up the parser:
>> >>>>
>> >>>> System.setProperty("javax.xml.validation.SchemaFactory:http://www.
>> >>>> w3.org/2001/XMLSchema",
>> >>> "org.apache.xerces.jaxp.validation.XMLSchemaFactory");
>> >>>>
>> >>>> SAXParserFactory parserFactory = SAXParserFactory.newInstance();
>> >>>> parserFactory.setNamespaceAware(true);
>> >>>> parserFactory.setValidating(false);
>> >>>> parserFactory.setFeature
>> >>> ("http://apache.org/xml/features/validation/schema
>> >>>> ", true); parserFactory.setFeature
>> >>> ("http://xml.org/sax/features/validation
>> >>>> ", true);
>> >>>>
>> >>>> SchemaFactory schemaFactory =  SchemaFactory.newInstance("http:
>> >>>> //www.w3.org/2001/XMLSchema");
>> >>>> StreamSource soapSchemaSource = new StreamSource(new
>> >>>> ClassPathResource(soapSchemaVersion).getInputStream());
>> >>>> soapSchemaSource.setSystemId
>> >>> ("http://schemas.xmlsoap.org/soap/envelope/";);
>> >>>>
>> >>>> StreamSource schemaSource = new StreamSource(new
>> >>>> ClassPathResource("arm-internal.xsd").getInputStream());));
>> >>>> schemaSource.setSystemId("http://service.arm.hud.gov/";);
>> >>>>
>> >>>> parserFactory.setSchema(schemaFactory.newSchema(new Source[]
>> >>>> {schemaSource, soapSchemaSource}));
>> >>>>
>> >>>> XMLReader reader = parserFactory.newSAXParser().getXMLReader();
>> >>>> ArmHandler handler = new ArmHandler();
>> >>>> reader.setErrorHandler(handler);
>> >>>> reader.parse(new InputSource(payload));
>> >>>>
>> >>>> I get no errors setting up my schema but yet when I try to parse a
>> >>>> XML file using the schema specified in newSchema, I get the
>> >>>> following exception:
>> >>>>
>> >>>> "org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace
>> >>>> characters are not allowed in schema elements other than 'xs:
>> >>>> appinfo' and 'xs:documentation'. Saw 'OpenDNS'"
>> >>>>
>> >>>> It is followed by a stack trace.
>> >>>> My schema actually imports 2 external schemas and when I specify
>> >>>> their schema location as a URL, not a local file, it works but i can
>> >>>> not rely on that because I do not have access to the internet.
>> >>>>
>> >>>> I can attach my XML and XSD files but there is no place to do so. I
>> >>>> will add them at the end.
>> >>>>
>> >>>> Here are my questions/issues:
>> >>>>
>> >>>> 1. How do I solve the problem above from happening other than
>> >>>> relying on the internet to find the schema.
>> >>>> 2. When I do modify my XML file, the above exception is corrected
>> >>>> but then I get an error saying it can not resolve the soapenv
>> >>>> namespace.
>> >>>> 3. Ultimately what I am interested in is getting the parser to
>> >>>> validate my XML correctly. It is intentionally flawed - there is a
>> >>>> bug in our system I am trying to correct. We were previously using
>> >>>> XMLValidator (from Spring) but it has no ability to
>> >>>> configure/customize so I switched to use the SAXParser. Ultimately,
>> >>>> I need the validator to complain when an element is missing. In my
>> >>>> XML below, I am missing the required element of referenceId but the
>> >>>> parser does not complain about it. Incidentally, it does not matter
>> >>>> if I supply the namespace or not in my XML file since I am
>> >>>> specifying the XSD in the application code in terms of it validating
>> >>>> the XML correctly.
>> >>>>
>> >>>> Thank you so much
>> >>>> Brenda
>> >>>
>> >>  http://www.nabble.com/file/p25978879/SAXParseException.txt
>> >> SAXParseException.txt
>> >>
>> >  http://www.nabble.com/file/p25978928/xmime.xsd xmime.xsd
>> > http://www.nabble.com/file/p25978928/xop-include.xsd xop-include.xsd
>> >
>>
>> --
>> View this message in context: http://www.nabble.com/SAXParser-
>> Problem-tp25961802p25979459.html
>> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
> 

-- 
View this message in context: 
http://www.nabble.com/SAXParser-Problem-tp25961802p25992119.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to