View | Details | Raw Unified | Return to bug 61630
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java (-16 / +18 lines)
Lines 436-464 Link Here
436
            return -1;
436
            return -1;
437
        }
437
        }
438
438
439
        NodeList list  = complexType.getChildNodes();
440
        int indexOf = -1;
439
        int indexOf = -1;
440
        int i = 0;
441
        Node node = complexType.getFirstChild();
442
        final String elementNameWithoutNamespace = removeNamespace(elementName);
441
443
442
        for(int i=0; i< list.getLength();i++) {
444
        while (node != null) {
443
            Node node = list.item(i);
444
            if (node instanceof Element && "element".equals(node.getLocalName())) {
445
            if (node instanceof Element && "element".equals(node.getLocalName())) {
445
                Node element = getNameOrRefElement(node);
446
                Node element = getNameOrRefElement(node);
446
                if (element.getNodeValue().equals(removeNamespace(elementName))) {
447
                if (element.getNodeValue().equals(elementNameWithoutNamespace)) {
447
                    indexOf = i;
448
                    indexOf = i;
448
                    break;
449
                    break;
449
                }
450
                }
450
            }
451
            }
452
            i++;
453
            node = node.getNextSibling();
451
        }
454
        }
452
        return indexOf;
455
        return indexOf;
453
    }
456
    }
454
457
455
	private Node getNameOrRefElement(Node node) {
458
	private Node getNameOrRefElement(Node node) {
456
		Node returnNode = node.getAttributes().getNamedItem("name");
459
		Node returnNode = node.getAttributes().getNamedItem("ref");
457
        if(returnNode != null) {
460
        if(returnNode != null) {
458
            return returnNode;
461
            return returnNode;
459
		}
462
		}
460
		
463
		
461
        return node.getAttributes().getNamedItem("ref");
464
        return node.getAttributes().getNamedItem("name");
462
	}
465
	}
463
466
464
    private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
467
    private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
Lines 482-492 Link Here
482
            return "";
485
            return "";
483
        }
486
        }
484
487
485
        NodeList  list  = localComplexTypeRootNode.getChildNodes();
488
        Node node  = localComplexTypeRootNode.getFirstChild();
486
        String complexTypeName = "";
489
        String complexTypeName = "";
487
490
488
        for(int i=0; i<list.getLength(); i++) {
491
        while (node != null) {
489
            final Node node = list.item(i);
490
            if ( node instanceof Element && "element".equals(node.getLocalName())) {
492
            if ( node instanceof Element && "element".equals(node.getLocalName())) {
491
                Node nameAttribute = getNameOrRefElement(node);
493
                Node nameAttribute = getNameOrRefElement(node);
492
                if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
494
                if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
Lines 497-502 Link Here
497
                    }
499
                    }
498
                }
500
                }
499
            }
501
            }
502
            node = node.getNextSibling();
500
        }
503
        }
501
        return complexTypeName;
504
        return complexTypeName;
502
    }
505
    }
Lines 503-520 Link Here
503
506
504
    private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode,
507
    private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode,
505
            String complexTypeName) {
508
            String complexTypeName) {
506
        NodeList  complexTypeList  = xmlSchema.getChildNodes();
509
        Node node = xmlSchema.getFirstChild();
507
        for(int i=0; i< complexTypeList.getLength();i++) {
510
        while (node != null) {
508
            Node node = complexTypeList.item(i);
509
            if ( node instanceof Element) {
511
            if ( node instanceof Element) {
510
                if ("complexType".equals(node.getLocalName())) {
512
                if ("complexType".equals(node.getLocalName())) {
511
                    Node nameAttribute = getNameOrRefElement(node);
513
                    Node nameAttribute = getNameOrRefElement(node);
512
                    if (nameAttribute.getNodeValue().equals(complexTypeName)) {
514
                    if (nameAttribute.getNodeValue().equals(complexTypeName)) {
515
                        Node sequence = node.getFirstChild();
516
                        while(sequence != null) {
513
517
514
                        NodeList complexTypeChildList  =node.getChildNodes();
515
                        for(int j=0; j<complexTypeChildList.getLength();j++) {
516
                            Node sequence = complexTypeChildList.item(j);
517
518
                            if ( sequence instanceof Element) {
518
                            if ( sequence instanceof Element) {
519
                                final String localName = sequence.getLocalName();
519
                                final String localName = sequence.getLocalName();
520
                                if ("sequence".equals(localName) || "all".equals(localName)) {
520
                                if ("sequence".equals(localName) || "all".equals(localName)) {
Lines 522-527 Link Here
522
                                    break;
522
                                    break;
523
                                }
523
                                }
524
                            }
524
                            }
525
                            sequence = sequence.getNextSibling();
525
                        }
526
                        }
526
                        if (complexTypeNode!=null) {
527
                        if (complexTypeNode!=null) {
527
                            break;
528
                            break;
Lines 530-535 Link Here
530
                    }
531
                    }
531
                }
532
                }
532
            }
533
            }
534
            node = node.getNextSibling();
533
        }
535
        }
534
        return complexTypeNode;
536
        return complexTypeNode;
535
    }
537
    }

Return to bug 61630