in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/docpath/DomBuilderFromSax.java [134:215]
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
addContentToCurrentElement(false);
final Element element = document.createElementNS((uri.length() == 0) ? null : uri, qName);
// Define New Prefixes
for (String newPrefix : newPrefixes) {
final String namespace = nsContext.getNamespaceURI(newPrefix);
if (namespace == null) {
throw new SAXException("Prefix " + newPrefix + " is not recognized.");
}
String qualifiedName = null;
if (newPrefix.length() > 0) {
qualifiedName = Constants.XMLNS_ATTRIBUTE + ':' + newPrefix;
} else {
qualifiedName = Constants.XMLNS_ATTRIBUTE;
}
try {
element.setAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, qualifiedName, namespace);
} catch (DOMException e) {
throw new IllegalStateException("Cannot add namespace attribute ns=\""
+ Constants.XMLNS_ATTRIBUTE_NS_URI + "\", qn=\""
+ qualifiedName + "\", value=\"" + namespace
+ "\" to element \"" + qName + "\".", e);
}
}
newPrefixes.clear();
// Add Attributes
final QName elemQName = new QName(uri, localName);
XmlSchemaStateMachineNode stateMachine = null;
if (elementsByQName != null) {
stateMachine = elementsByQName.get(elemQName);
}
for (int attrIndex = 0; attrIndex < atts.getLength(); ++attrIndex) {
String attrUri = atts.getURI(attrIndex);
if (attrUri.length() == 0) {
attrUri = null;
}
boolean isGlobal = globalNamespaces.contains(attrUri);
if ((attrUri != null) && !isGlobal) {
final QName attrQName = new QName(attrUri, atts.getLocalName(attrIndex));
boolean found = false;
if (stateMachine != null) {
for (XmlSchemaAttrInfo attrInfo : stateMachine.getAttributes()) {
if (attrInfo.getAttribute().getQName().equals(attrQName)) {
found = true;
isGlobal = attrInfo.isTopLevel();
}
}
}
if (!found && (schemas.getAttributeByQName(attrQName) != null)) {
isGlobal = true;
}
}
final String attrValue = atts.getValue(attrIndex);
if (!isGlobal) {
element.setAttribute(atts.getLocalName(attrIndex), attrValue);
} else {
element.setAttributeNS(attrUri, atts.getQName(attrIndex), attrValue);
}
}
// Update the Parent Element
if (!elementStack.isEmpty()) {
elementStack.get(elementStack.size() - 1).appendChild(element);
} else {
addNamespaceLocationMappings(element);
document.appendChild(element);
}
elementStack.add(element);
}