String tagPrefix = elementSchema.getTagPrefix();
DocType docType = element.getDocType();
if (docType != null) {
values.add(flattenDocType(element, docType));
}
values.add(new StringConstant(element, elementSchema, "<"));
if (tagPrefix != null) {
values.add(new StringConstant(element, elementSchema, tagPrefix + ":"));
}
values.add(new StringConstant(element, elementSchema,
element.getLocalName()));
if (docType != null) {
values.add(flattenXmlns(element));
}
for (final Attribute attr : element.getAttributes()) {
AttributeValidator attrValidator = elementValidator.getAttributeValidator(attr.getName());
Expression empty = new StringConstant(attr, elementSchema, "");
if (attrValidator.isFlagSet(AttributeValidator.Flag.BOOLEAN)) {
Expression attrValue = attr.getValue().acceptVisitor(this);
if (attrValue.hasStaticString()) {
values.add(buildBooleanAttrExpression(attr, element));
} else {
if (attrValue instanceof ConvertibleToContent) {
ConvertibleToContent ctc = (ConvertibleToContent)attrValue;
attrValue = ctc.getSubexpression();
}
values.add(new Conditional(element, elementSchema,
attrValue,
buildBooleanAttrExpression(attr, element),
empty));
}
} else {
Expression condition = attr.getCondition();
if (condition != null) {
values.add(new Conditional(element, elementSchema, condition,
buildAttrExpression(attr, element), empty));
} else {
values.add(buildAttrExpression(attr, element));
}
}
}
for (String attrBundle : element.getAttrBundles()) {
values.add(new EscapeExpression(elementSchema,
new AttrBundleReference(element, attrBundle)));
}
if (elementValidator.isFlagSet(ElementValidator.Flag.NOENDTAG)) {
values.add(new Conditional(
element, elementSchema,
new IsXmlExpression(element, elementSchema),
new StringConstant(element, elementSchema, " /"),
new StringConstant(element, elementSchema, "")));
}
values.add(new StringConstant(element, elementSchema, ">"));
values.add(element.getContent().acceptVisitor(this));
if (!elementValidator.isFlagSet(ElementValidator.Flag.NOENDTAG)) {
values.add(new StringConstant(element, elementSchema, "</"));
if (tagPrefix != null) {
values.add(new StringConstant(element, elementSchema,
tagPrefix + ":"));
}
values.add(new StringConstant(element, elementSchema,
element.getLocalName() + ">"));
}
return Concatenation.create(element.getSourcePosition(), elementSchema, values);
}