in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/docpath/DomBuilderFromSax.java [279:323]
private void addContentToCurrentElement(boolean isEnd) {
if ((content == null) || (content.length() == 0)) {
/*
* If we reached the end of the element, check if we received any
* content. If not, and if the element is nillable, write a nil
* attribute.
*/
if (isEnd && !elementStack.isEmpty() && (schemas != null)) {
final Element currElem = elementStack.get(elementStack.size() - 1);
if (currElem.getChildNodes().getLength() == 0) {
final QName elemQName = new QName(currElem.getNamespaceURI(), currElem.getLocalName());
XmlSchemaElement schemaElem = null;
if (elementsByQName != null) {
final XmlSchemaStateMachineNode stateMachine = elementsByQName.get(elemQName);
if ((stateMachine != null)
&& stateMachine.getNodeType().equals(XmlSchemaStateMachineNode.Type.ELEMENT)) {
schemaElem = stateMachine.getElement();
}
}
if (schemaElem == null) {
schemaElem = schemas.getElementByQName(elemQName);
}
if ((schemaElem != null) && schemaElem.isNillable()) {
currElem.setAttributeNS(XSI_NS, XSI_NIL, "true");
}
}
}
return;
}
if (elementStack.isEmpty()) {
StringBuilder errMsg = new StringBuilder("Attempted to add content \"");
errMsg.append(content.toString()).append("\", but there were no ");
errMsg.append("elements in the stack!");
throw new IllegalStateException(errMsg.toString());
}
elementStack.get(elementStack.size() - 1).appendChild(document.createTextNode(content.toString()));
content.delete(0, content.length());
}