Node node = list.item(i);
if (node instanceof Element) {
if (node.getLocalName().equals("element")) {
- Node nameAttribute = node.getAttributes().getNamedItem("name");
- if (nameAttribute.getNodeValue().equals(removeNamespace(elementName))) {
+ Node element = getNameOrRefElement(node);
+ if (element.getNodeValue().equals(removeNamespace(elementName))) {
indexOf = i;
break;
}
return indexOf;
}
+ private Node getNameOrRefElement(Node node) {
+ Node returnNode = node.getAttributes().getNamedItem("name");
+ if(returnNode != null) {
+ return returnNode;
+ }
+
+ return node.getAttributes().getNamedItem("ref");
+ }
+
private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
String elementNameWithoutNamespace = removeNamespace(elementName);
Node node = list.item(i);
if ( node instanceof Element) {
if (node.getLocalName().equals("element")) {
- Node nameAttribute = node.getAttributes().getNamedItem("name");
+ Node nameAttribute = getNameOrRefElement(node);
if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
Node complexTypeAttribute = node.getAttributes().getNamedItem("type");
if (complexTypeAttribute!=null) {
Node node = complexTypeList.item(i);
if ( node instanceof Element) {
if (node.getLocalName().equals("complexType")) {
- Node nameAttribute = node.getAttributes().getNamedItem("name");
+ Node nameAttribute = getNameOrRefElement(node);
if (nameAttribute.getNodeValue().equals(complexTypeName)) {
NodeList complexTypeChildList =node.getChildNodes();
* @author Roberto Manicardi
*/
public final class TestXSSFExportToXML extends TestCase {
- public void testExportToXML() throws Exception {
+
+ public void testExportToXML() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings.xlsx");
}
assertTrue(found);
}
+
+ public void testRefElementsInXmlSchema_Bugzilla_56730() throws Exception {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56730.xlsx");
+
+ boolean found = false;
+ for (POIXMLDocumentPart p : wb.getRelations()) {
+
+ if (!(p instanceof MapInfo)) {
+ continue;
+ }
+ MapInfo mapInfo = (MapInfo) p;
+
+ XSSFMap map = mapInfo.getXSSFMapById(1);
+
+ assertNotNull("XSSFMap is null", map);
+
+ XSSFExportToXml exporter = new XSSFExportToXml(map);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ exporter.exportToXML(os, true);
+ String xmlData = os.toString("UTF-8");
+
+ assertNotNull(xmlData);
+ assertFalse(xmlData.equals(""));
+
+ assertEquals("2014-12-31", xmlData.split("<DATE>")[1].split("</DATE>")[0].trim());
+ assertEquals("12.5", xmlData.split("<REFELEMENT>")[1].split("</REFELEMENT>")[0].trim());
+
+ parseXML(xmlData);
+
+ found = true;
+ }
+ assertTrue(found);
+ }
}