Search in sources :

Example 1 with XmlAttr

use of nokogiri.XmlAttr in project gocd by gocd.

the class ReaderNode method getAttributesNodes.

public IRubyObject getAttributesNodes() {
    RubyArray array = RubyArray.newArray(ruby);
    if (attributeList != null && attributeList.length > 0) {
        if (document == null) {
            XmlDocument doc = (XmlDocument) XmlDocument.rbNew(ruby.getCurrentContext(), getNokogiriClass(ruby, "Nokogiri::XML::Document"), new IRubyObject[0]);
            document = doc.getDocument();
        }
        for (int i = 0; i < attributeList.length; i++) {
            if (!isNamespace(attributeList.names.get(i))) {
                Attr attr = document.createAttributeNS(attributeList.namespaces.get(i), attributeList.names.get(i));
                attr.setValue(attributeList.values.get(i));
                XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Attr"));
                xmlAttr.setNode(ruby.getCurrentContext(), attr);
                array.append(xmlAttr);
            }
        }
    }
    return array;
}
Also used : RubyArray(org.jruby.RubyArray) XmlDocument(nokogiri.XmlDocument) IRubyObject(org.jruby.runtime.builtin.IRubyObject) XmlAttr(nokogiri.XmlAttr) Attr(org.w3c.dom.Attr) XmlAttr(nokogiri.XmlAttr)

Example 2 with XmlAttr

use of nokogiri.XmlAttr in project gocd by gocd.

the class NokogiriHelpers method constructNode.

/**
     * Construct a new XmlNode wrapping <code>node</code>.  The proper
     * subclass of XmlNode is chosen based on the type of
     * <code>node</code>.
     */
public static IRubyObject constructNode(Ruby runtime, Node node) {
    if (node == null)
        return runtime.getNil();
    // this is slow; need a way to cache nokogiri classes/modules somewhere
    switch(node.getNodeType()) {
        case Node.ELEMENT_NODE:
            XmlElement xmlElement = (XmlElement) NokogiriService.XML_ELEMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Element"));
            xmlElement.setNode(runtime.getCurrentContext(), node);
            return xmlElement;
        case Node.ATTRIBUTE_NODE:
            XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Attr"));
            xmlAttr.setNode(runtime.getCurrentContext(), node);
            return xmlAttr;
        case Node.TEXT_NODE:
            XmlText xmlText = (XmlText) NokogiriService.XML_TEXT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Text"));
            xmlText.setNode(runtime.getCurrentContext(), node);
            return xmlText;
        case Node.COMMENT_NODE:
            XmlComment xmlComment = (XmlComment) NokogiriService.XML_COMMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Comment"));
            xmlComment.setNode(runtime.getCurrentContext(), node);
            return xmlComment;
        case Node.ENTITY_NODE:
            return new XmlNode(runtime, getNokogiriClass(runtime, "Nokogiri::XML::EntityDecl"), node);
        case Node.ENTITY_REFERENCE_NODE:
            XmlEntityReference xmlEntityRef = (XmlEntityReference) NokogiriService.XML_ENTITY_REFERENCE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::EntityReference"));
            xmlEntityRef.setNode(runtime.getCurrentContext(), node);
            return xmlEntityRef;
        case Node.PROCESSING_INSTRUCTION_NODE:
            XmlProcessingInstruction xmlProcessingInstruction = (XmlProcessingInstruction) NokogiriService.XML_PROCESSING_INSTRUCTION_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::ProcessingInstruction"));
            xmlProcessingInstruction.setNode(runtime.getCurrentContext(), node);
            return xmlProcessingInstruction;
        case Node.CDATA_SECTION_NODE:
            XmlCdata xmlCdata = (XmlCdata) NokogiriService.XML_CDATA_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::CDATA"));
            xmlCdata.setNode(runtime.getCurrentContext(), node);
            return xmlCdata;
        case Node.DOCUMENT_NODE:
            XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"));
            xmlDocument.setDocumentNode(runtime.getCurrentContext(), node);
            return xmlDocument;
        case Node.DOCUMENT_TYPE_NODE:
            XmlDtd xmlDtd = (XmlDtd) NokogiriService.XML_DTD_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::DTD"));
            xmlDtd.setNode(runtime, node);
            return xmlDtd;
        default:
            XmlNode xmlNode = (XmlNode) NokogiriService.XML_NODE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Node"));
            xmlNode.setNode(runtime.getCurrentContext(), node);
            return xmlNode;
    }
}
Also used : XmlDtd(nokogiri.XmlDtd) XmlNode(nokogiri.XmlNode) XmlEntityReference(nokogiri.XmlEntityReference) XmlProcessingInstruction(nokogiri.XmlProcessingInstruction) XmlComment(nokogiri.XmlComment) XmlElement(nokogiri.XmlElement) XmlText(nokogiri.XmlText) XmlDocument(nokogiri.XmlDocument) XmlAttr(nokogiri.XmlAttr) XmlCdata(nokogiri.XmlCdata)

Example 3 with XmlAttr

use of nokogiri.XmlAttr in project nokogiri by sparklemotion.

the class ReaderNode method getAttributesNodes.

public IRubyObject getAttributesNodes() {
    RubyArray array = RubyArray.newArray(ruby);
    if (attributeList != null && attributeList.length > 0) {
        if (document == null) {
            XmlDocument doc = (XmlDocument) XmlDocument.rbNew(ruby.getCurrentContext(), getNokogiriClass(ruby, "Nokogiri::XML::Document"), new IRubyObject[0]);
            document = doc.getDocument();
        }
        for (int i = 0; i < attributeList.length; i++) {
            if (!isNamespace(attributeList.names.get(i))) {
                Attr attr = document.createAttributeNS(attributeList.namespaces.get(i), attributeList.names.get(i));
                attr.setValue(attributeList.values.get(i));
                XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Attr"));
                xmlAttr.setNode(ruby.getCurrentContext(), attr);
                array.append(xmlAttr);
            }
        }
    }
    return array;
}
Also used : RubyArray(org.jruby.RubyArray) XmlDocument(nokogiri.XmlDocument) IRubyObject(org.jruby.runtime.builtin.IRubyObject) XmlAttr(nokogiri.XmlAttr) Attr(org.w3c.dom.Attr) XmlAttr(nokogiri.XmlAttr)

Example 4 with XmlAttr

use of nokogiri.XmlAttr in project nokogiri by sparklemotion.

the class NokogiriHelpers method constructNode.

/**
     * Construct a new XmlNode wrapping <code>node</code>.  The proper
     * subclass of XmlNode is chosen based on the type of
     * <code>node</code>.
     */
public static IRubyObject constructNode(Ruby runtime, Node node) {
    if (node == null)
        return runtime.getNil();
    // this is slow; need a way to cache nokogiri classes/modules somewhere
    switch(node.getNodeType()) {
        case Node.ELEMENT_NODE:
            XmlElement xmlElement = (XmlElement) NokogiriService.XML_ELEMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Element"));
            xmlElement.setNode(runtime.getCurrentContext(), node);
            return xmlElement;
        case Node.ATTRIBUTE_NODE:
            XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Attr"));
            xmlAttr.setNode(runtime.getCurrentContext(), node);
            return xmlAttr;
        case Node.TEXT_NODE:
            XmlText xmlText = (XmlText) NokogiriService.XML_TEXT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Text"));
            xmlText.setNode(runtime.getCurrentContext(), node);
            return xmlText;
        case Node.COMMENT_NODE:
            XmlComment xmlComment = (XmlComment) NokogiriService.XML_COMMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Comment"));
            xmlComment.setNode(runtime.getCurrentContext(), node);
            return xmlComment;
        case Node.ENTITY_NODE:
            return new XmlNode(runtime, getNokogiriClass(runtime, "Nokogiri::XML::EntityDecl"), node);
        case Node.ENTITY_REFERENCE_NODE:
            XmlEntityReference xmlEntityRef = (XmlEntityReference) NokogiriService.XML_ENTITY_REFERENCE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::EntityReference"));
            xmlEntityRef.setNode(runtime.getCurrentContext(), node);
            return xmlEntityRef;
        case Node.PROCESSING_INSTRUCTION_NODE:
            XmlProcessingInstruction xmlProcessingInstruction = (XmlProcessingInstruction) NokogiriService.XML_PROCESSING_INSTRUCTION_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::ProcessingInstruction"));
            xmlProcessingInstruction.setNode(runtime.getCurrentContext(), node);
            return xmlProcessingInstruction;
        case Node.CDATA_SECTION_NODE:
            XmlCdata xmlCdata = (XmlCdata) NokogiriService.XML_CDATA_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::CDATA"));
            xmlCdata.setNode(runtime.getCurrentContext(), node);
            return xmlCdata;
        case Node.DOCUMENT_NODE:
            XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"));
            xmlDocument.setDocumentNode(runtime.getCurrentContext(), node);
            return xmlDocument;
        case Node.DOCUMENT_TYPE_NODE:
            XmlDtd xmlDtd = (XmlDtd) NokogiriService.XML_DTD_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::DTD"));
            xmlDtd.setNode(runtime, node);
            return xmlDtd;
        default:
            XmlNode xmlNode = (XmlNode) NokogiriService.XML_NODE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Node"));
            xmlNode.setNode(runtime.getCurrentContext(), node);
            return xmlNode;
    }
}
Also used : XmlDtd(nokogiri.XmlDtd) XmlNode(nokogiri.XmlNode) XmlEntityReference(nokogiri.XmlEntityReference) XmlProcessingInstruction(nokogiri.XmlProcessingInstruction) XmlComment(nokogiri.XmlComment) XmlElement(nokogiri.XmlElement) XmlText(nokogiri.XmlText) XmlDocument(nokogiri.XmlDocument) XmlAttr(nokogiri.XmlAttr) XmlCdata(nokogiri.XmlCdata)

Aggregations

XmlAttr (nokogiri.XmlAttr)4 XmlDocument (nokogiri.XmlDocument)4 XmlCdata (nokogiri.XmlCdata)2 XmlComment (nokogiri.XmlComment)2 XmlDtd (nokogiri.XmlDtd)2 XmlElement (nokogiri.XmlElement)2 XmlEntityReference (nokogiri.XmlEntityReference)2 XmlNode (nokogiri.XmlNode)2 XmlProcessingInstruction (nokogiri.XmlProcessingInstruction)2 XmlText (nokogiri.XmlText)2 RubyArray (org.jruby.RubyArray)2 IRubyObject (org.jruby.runtime.builtin.IRubyObject)2 Attr (org.w3c.dom.Attr)2