if (nodes.getLength() > 0) {
return nodes;
}
}
XMLNodeList elementsToReturn = new XMLNodeList();
if (value == this) {
String namespace = resolveNamespacePrefix(fragment, getNamespaceResolverForField(xmlField));
Element newElement = parent.getOwnerDocument().createElementNS(namespace, fragment.getShortName());
XPathPredicate predicate = fragment.getPredicate();
if(predicate != null) {
XPathFragment predicateFragment = predicate.getXPathFragment();
if(predicateFragment.isAttribute()) {
if(predicateFragment.getNamespaceURI() == null || predicateFragment.getNamespaceURI().length() == 0) {
newElement.setAttribute(predicateFragment.getLocalName(), fragment.getPredicate().getValue());
} else {
String name = predicateFragment.getLocalName();
if(predicateFragment.getPrefix() != null && predicateFragment.getPrefix().length() != 0) {
name = predicateFragment.getPrefix() + XMLConstants.COLON + name;
}
newElement.setAttributeNS(predicateFragment.getNamespaceURI(), name, fragment.getPredicate().getValue());
}
}
}
elementsToReturn.add(newElement);
docPresPolicy.getNodeOrderingPolicy().appendNode(parent, newElement, sibling);
} else if (value == null) {
elementsToReturn.add(parent);
} else {
// Value may be a direct value, node, or list of values.
if (value instanceof List) {
List values = (List)value;
for (int index = 0; index < values.size(); index++) {
Element newElement = null;
if (values.get(index) != XMLRecord.NIL) {
newElement = (Element) createElement(parent, fragment, xmlField, values.get(index), session);
} else {
newElement = (Element) createElement(parent, fragment, xmlField, XMLConstants.EMPTY_STRING, session);
newElement.setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_INSTANCE_PREFIX + ":" + XMLConstants.SCHEMA_NIL_ATTRIBUTE, XMLConstants.BOOLEAN_STRING_TRUE);
}
XPathPredicate predicate = fragment.getPredicate();
if(predicate != null) {
XPathFragment predicateFragment = predicate.getXPathFragment();
if(predicateFragment.isAttribute()) {
if(predicateFragment.getNamespaceURI() == null || predicateFragment.getNamespaceURI().length() == 0) {
newElement.setAttribute(predicateFragment.getLocalName(), fragment.getPredicate().getValue());
} else {
String name = predicateFragment.getLocalName();
if(predicateFragment.getPrefix() != null && predicateFragment.getPrefix().length() != 0) {
name = predicateFragment.getPrefix() + XMLConstants.COLON + name;
}
newElement.setAttributeNS(predicateFragment.getNamespaceURI(), name, fragment.getPredicate().getValue());
}
}
}
docPresPolicy.getNodeOrderingPolicy().appendNode(parent, newElement, sibling);
elementsToReturn.add(newElement);
sibling = newElement;
}
} else {
Element newElement = null;
if (value != XMLRecord.NIL) {
newElement = (Element)createElement(parent, fragment, xmlField, value, session);
} else {
newElement = (Element) createElement(parent, fragment, xmlField, XMLConstants.EMPTY_STRING, session);
newElement.setAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_INSTANCE_PREFIX + ":" + XMLConstants.SCHEMA_NIL_ATTRIBUTE, XMLConstants.BOOLEAN_STRING_TRUE);
}
XPathPredicate predicate = fragment.getPredicate();
if(predicate != null) {
XPathFragment predicateFragment = predicate.getXPathFragment();
if(predicateFragment.isAttribute()) {
if(predicateFragment.getNamespaceURI() == null || predicateFragment.getNamespaceURI().length() == 0) {
newElement.setAttribute(predicateFragment.getLocalName(), fragment.getPredicate().getValue());
} else {
String name = predicateFragment.getLocalName();
if(predicateFragment.getPrefix() != null && predicateFragment.getPrefix().length() != 0) {
name = predicateFragment.getPrefix() + XMLConstants.COLON + name;
}
newElement.setAttributeNS(predicateFragment.getNamespaceURI(), name, fragment.getPredicate().getValue());
}
}
}
docPresPolicy.getNodeOrderingPolicy().appendNode(parent, newElement, sibling);
elementsToReturn.add(newElement);
}
}
return elementsToReturn;
}