It did not add the default element value :o(
What I have is:
System.setProperty(DOMImplementationRegistry.PROPERTY,"org.apache.xerces
.dom.DOMXSImplementationSourceImpl");
System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org
/2001/XMLSchema", "org.apache.xerces.jaxp.validation.XMLSchemaFactory");
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS)registry.getDOMImplementation("LS");
// create DOMBuilder
LSParser builder =
impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = builder.getDomConfig();
builder.setFilter(skipWhitespaceFilter);
// Create the document builder
JMSErrorHandler2 errorHandler = new JMSErrorHandler2();
config.setParameter("error-handler", errorHandler);
config.setParameter("http://xml.org/sax/features/validation", true);
config.setParameter("http://apache.org/xml/features/validation/schema",
true);
config.setParameter("http://apache.org/xml/features/validation/schema/el
ement-default", true);
// Parse the xml file
Document doc = null;
LSInput input = impl.createLSInput();
if (xml instanceof File) {
input.setByteStream(new FileInputStream((File)xml));
} else if (xml instanceof String) {
input.setCharacterStream(new StringReader((String)xml));
}
doc = builder.parse(input);
// Create the schema factory
SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// Create the schema object
Schema schema = schemaFactory.newSchema(new File(schemaLocation));
// Create the validator
Validator validator = schema.newValidator();
// Add an error handler to the validator
JMSErrorHandler v_errorHandler = new JMSErrorHandler();
validator.setErrorHandler(v_errorHandler);
// Create the dom source and destination
// The destination will contain the doc augmented with the default
attribute/element
DOMSource source = new DOMSource(doc);
DOMResult result = new DOMResult();
// Validate and augment the source
validator.validate(source, result);
// Error checking
if ( v_errorHandler.validationError == true ) {
// errors occured during the parsing
if (myLogger.isInfoEnabled()) {
myLogger.info(funcName + "XML file is not valid - Got a
validation error");
myLogger.info(v_errorHandler.saxParseException.getMessage());
}
Throw new NBIErrException("XML file not valid " +
v_errorHandler.saxParseException.getMessage());
} else {
if (myLogger.isInfoEnabled()) {
myLogger.info(funcName + "XML file is valid");
}
// Return the augmented document
return (Document)result.getNode();
}
-----Original Message-----
From: Michael Glavassevich
Sent: Friday, October 13, 2006 06:20
To: [email protected]
Subject: RE: element-default with DOM3
Try setting
"http://apache.org/xml/features/validation/schema/element-default" as a
parameter with a Boolean value and see what happens.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]
"Decoker, Lydie \(Lydie\)" wrote on 10/12/2006
03:53:18 AM:
> Thx Michael. But looking the links provided, I do not see what could
> help me to add element default value in my DOM tree.
>
> I see that for LSSerialzer, you have an option
> "discard-default-content". If you set it to false, I should get the
> default value. But from what I understand LSSerializer will output a
> string but I want to keep my DOM tree.
>
> Lydie.
>
> -----Original Message-----
> From: Michael Glavassevich [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, October 11, 2006 19:00
> To: [email protected]
> Subject: Re: element-default with DOM3
>
> "Decoker, Lydie \(Lydie\)" wrote on 10/11/2006
> 09:32:39 AM:
>
> > Hello!
> >
> > I am using now the LSParser (in order to get rid of the empty text
> > node) adn LSParserFilter.
> > I am trying to replicate what I was doing with the DocumentBuilder.
> > To augment my xml with the default values, the feature I had set
was:
> >
> > domFactory.setFeature("http://apache.
> > org/xml/features/validation/schema/element-default",true);
> > Is there something similar for DOMImplementationLS used to create
> > the LSParser?
>
> See DOMConfiguration [1]. This is what you use to configure [2] an
> LSParser.
>
> > Thx in advance,
> >
> > Lydie
>
> [1] http://www.w3.org/TR/DOM-Level-3-Core/core.html#DOMConfiguration
> [2]
> http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html#L
> S-
> LSParser-config
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: [EMAIL PROTECTED]
> E-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]