}
private void visitAnyElement(List<Element> elements, int index) {
Element anyElement = elements.get(index);
String ns = anyElement.attribute("namespace").getValue();
ConfigurationPoint cp = cps.getConfigurationPointByNamespaceUri(ns);
if (cp != null) {
Element choiceElement = DocumentHelper.createElement(XSD_CHOICE);
String nsPrefix = getNamespacePrefix(cp.getPreferredNsPrefix(), ns);
// <xsd:schema xmlns:prefix="ns">
// 注意:必须将ns定义加在顶层element,否则低版本的xerces会报错。
root.addNamespace(nsPrefix, ns);
// <xsd:choice minOccurs="?" maxOccurs="?" />
if (anyElement.attribute("minOccurs") != null) {
choiceElement.addAttribute("minOccurs", anyElement.attribute("minOccurs").getValue());
}
if (anyElement.attribute("maxOccurs") != null) {
choiceElement.addAttribute("maxOccurs", anyElement.attribute("maxOccurs").getValue());
}
// <xsd:element ref="prefix:contrib" />
for (Contribution contrib : cp.getContributions()) {
Element elementElement = DocumentHelper.createElement(XSD_ELEMENT);
elementElement.addAttribute("ref", nsPrefix + ":" + contrib.getName());
choiceElement.add(elementElement);
}
// <xsd:element ref="prefix:defaultName" />
if (cp.getDefaultElementName() != null) {
Element elementElement = DocumentHelper.createElement(XSD_ELEMENT);
elementElement.addAttribute("ref", nsPrefix + ":" + cp.getDefaultElementName());
choiceElement.add(elementElement);
}
// 用choice取代any
elements.set(index, choiceElement);