Method: WirisPlugin::WXmlUtils.importXmlNamespace

Defined in:
lib/com/wiris/util/xml/WXmlUtils.rb

.importXmlNamespace(elem, model, customNamespace, prefixAttributes) ⇒ Object



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/com/wiris/util/xml/WXmlUtils.rb', line 560

def self.importXmlNamespace(elem, model, customNamespace, prefixAttributes)
    n = nil
    if elem::nodeType == Xml::Element
        n = model::createElement_((customNamespace + ":") + elem::nodeName.to_s)
        keys = elem::attributes()
        while keys::hasNext()
            key = keys::next()
            keyNamespaced = key
            if (prefixAttributes && (key::indexOf(":") == -1)) && (key::indexOf("xmlns") == -1)
                keyNamespaced = (customNamespace + ":") + key
            end
            n::set(keyNamespaced,elem::get(key))
        end
        children = elem::iterator()
        while children::hasNext()
            n::addChild(WXmlUtils.importXmlNamespace(children::next(),model,customNamespace,prefixAttributes))
        end
    else 
        if elem::nodeType == Xml::Document
            n = WXmlUtils.importXmlNamespace(elem::firstElement(),model,customNamespace,prefixAttributes)
        else 
            if elem::nodeType == Xml::CData
                n = model::createCData_(elem::getNodeValue_())
            else 
                if elem::nodeType == Xml::PCData
                    n = model::createPCData_(elem::getNodeValue_())
                else 
                    raise Exception,"Unsupported node type: " + elem::nodeType.to_s
                end
            end
        end
    end
    return n
end