Package nokogiri

Examples of nokogiri.XmlDocument


    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));
View Full Code Here


        doc.setInstanceVariable("@errors", errors);
    }

    public XmlDocument getDocumentWithErrorsOrRaiseException(ThreadContext context, RubyClass klazz, Exception ex) {
        if (options.recover) {
            XmlDocument xmlDocument = getInterruptedOrNewXmlDocument(context, klazz);
            this.addErrorsIfNecessary(context, xmlDocument);
            XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
            xmlSyntaxError.setException(ex);
            ((RubyArray) xmlDocument.getInstanceVariable("@errors")).append(xmlSyntaxError);
            return xmlDocument;
        } else {
            XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
            xmlSyntaxError.setException(ex);
            throw new RaiseException(xmlSyntaxError);
View Full Code Here

        }
    }
   
    private XmlDocument getInterruptedOrNewXmlDocument(ThreadContext context, RubyClass klazz) {
        Document document = parser.getDocument();
        XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
        if (document != null) {
            xmlDocument.setDocumentNode(context, document);
        }
        xmlDocument.setEncoding(ruby_encoding);
        return xmlDocument;
    }
View Full Code Here

     * override it.
     */
    protected XmlDocument wrapDocument(ThreadContext context,
                                       RubyClass klazz,
                                       Document doc) {
        XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
        xmlDocument.setDocumentNode(context, doc);
        xmlDocument.setEncoding(ruby_encoding);

        if (options.dtdLoad) {
            IRubyObject xmlDtdOrNil = XmlDtd.newFromExternalSubset(context.getRuntime(), doc);
            if (!xmlDtdOrNil.isNil()) {
                XmlDtd xmlDtd = (XmlDtd) xmlDtdOrNil;
View Full Code Here

     * Must call setInputSource() before this method.
     */
    public XmlDocument parse(ThreadContext context,
                             IRubyObject klazz,
                             IRubyObject url) {
        XmlDocument xmlDoc;
        try {
            Document doc = do_parse();
            xmlDoc = wrapDocument(context, (RubyClass)klazz, doc);
            xmlDoc.setUrl(url);
            addErrorsIfNecessary(context, xmlDoc);
            return xmlDoc;
        } catch (SAXException e) {
            return getDocumentWithErrorsOrRaiseException(context, (RubyClass)klazz, e);
        } catch (IOException e) {
View Full Code Here

     * value.
     */
    public static IRubyObject getCachedNodeOrCreate(Ruby ruby, Node node) {
        if(node == null) return ruby.getNil();
        if (node.getNodeType() == Node.ATTRIBUTE_NODE && isNamespace(node.getNodeName())) {
            XmlDocument xmlDocument = (XmlDocument)node.getOwnerDocument().getUserData(CACHED_NODE);
            if (!(xmlDocument instanceof HtmlDocument)) {
            String prefix = getLocalNameForNamespace(((Attr)node).getName());
            prefix = prefix != null ? prefix : "";
            String href = ((Attr)node).getValue();
            XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefix, href);
            if (xmlNamespace != null) return xmlNamespace;
            else return XmlNamespace.createFromAttr(ruby, (Attr)node);
            }
        }
        XmlNode xmlNode = getCachedNode(node);
View Full Code Here

            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;
View Full Code Here

    public static boolean shouldDecode(Node text) {
      return !shouldEncode(text);
    }

    public static NokogiriNamespaceCache getNamespaceCacheFormNode(Node n) {
        XmlDocument xmlDoc = (XmlDocument)getCachedNode(n.getOwnerDocument());
        return xmlDoc.getNamespaceCache();
    }
View Full Code Here

TOP

Related Classes of nokogiri.XmlDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.