Package nu.xom

Examples of nu.xom.Document


       
        // TODO point this, at least optionally, at the jaxen directory in the zip file instead.
        // However, first you'll have to push a jaxen 1.2.1 that fixes tests.xml.
        String base = "http://svn.jaxen.codehaus.org/browse/~raw,r=trunk/jaxen/trunk/jaxen/";
        Builder builder = new Builder();
        Document testDoc = builder.build(base + "xml/test/tests.xml");
        Elements documents = testDoc.getRootElement().getChildElements("document");
        for (int i = 0; i < documents.size(); i++) {
            Element documentElement = documents.get(i);
            String url = documentElement.getAttributeValue("url");
            Document source = builder.build(
              "http://svn.jaxen.codehaus.org/browse/~raw,r=trunk/jaxen/trunk/jaxen/"
              + url);
            Elements contextElements = documentElement.getChildElements("context");
            for (int j = 0; j < contextElements.size(); j++) {
                Element contextElement = contextElements.get(j);
                   
                // skip tests that use variables
                // because XOM doesn't support variables in
                // XPath expressions
                if (queryUsesVars(contextElement)) continue;
               
                String xpath = contextElement.getAttributeValue("select");
                XPathContext namespaces = getXPathContext(contextElement);
                Node context = source.query(xpath).get(0);
               
                // process counts
                Elements tests = contextElement.getChildElements("test");
                for (int k = 0; k < tests.size(); k++) {
                    Element test = tests.get(k);
View Full Code Here


   
   
    public void testTextChildInPredicate() {
       
        Element item = new Element("item");
        Document doc = new Document(item);
        Element name = new Element("name");
        name.appendChild("a");
        item.appendChild(name);
        Element value = new Element("value");
        value.appendChild("b");
        item.appendChild(value);
        Nodes result = doc.query("/item[name/text()='a']/value");
        assertEquals(1, result.size());
        assertEquals("b", result.get(0).getValue());
       
    }
View Full Code Here

   
    public void testSimpleTextChildInPredicate() {
       
        Element item = new Element("item");
        Document doc = new Document(item);
        item.appendChild("a");
        Nodes result = doc.query("/item[text()='a']");
        assertEquals(1, result.size());
       
    }
View Full Code Here

   
   
    public void testPrecedingAxisInDocumentOrder() {
   
        Element root = new Element("root");
        new Document(root);
       
        Element a = new Element("a");
        root.appendChild(a);
        Element b = new Element("b");
        root.appendChild(b);
View Full Code Here

            org.w3c.dom.Node node = ((DOMSource) requestPayload).getNode();
            if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
                return DOMConverter.convert((org.w3c.dom.Element) node);
            }
            else if (node.getNodeType() == org.w3c.dom.Node.DOCUMENT_NODE) {
                Document document = DOMConverter.convert((org.w3c.dom.Document) node);
                return document.getRootElement();
            }
        }
        // we have no other option than to transform
        ByteArrayInputStream bis = convertToByteArrayInputStream(requestPayload);
        Builder builder = new Builder();
        Document document = builder.build(bis);
        return document.getRootElement();
    }
View Full Code Here

    @Override
    protected Source createResponsePayload(MethodParameter returnType, Object returnValue)
            throws ParserConfigurationException {
        Element returnedElement = (Element) returnValue;
        Document document = returnedElement.getDocument();
        if (document == null) {
            document = new Document(returnedElement);
        }
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        DOMImplementation domImplementation = documentBuilder.getDOMImplementation();
        org.w3c.dom.Document w3cDocument = DOMConverter.convert(document, domImplementation);
        return new DOMSource(w3cDocument);
View Full Code Here

        @Override
        public void streamSource(InputStream inputStream) throws IOException {
            try {
                Builder builder = new Builder();
                Document document = builder.build(inputStream);
                element = document.getRootElement();
            }
            catch (ParsingException ex) {
                throw new XomParsingException(ex);
            }
        }
View Full Code Here

        @Override
        public void streamSource(Reader reader) throws IOException {
            try {
                Builder builder = new Builder();
                Document document = builder.build(reader);
                element = document.getRootElement();
            }
            catch (ParsingException ex) {
                throw new XomParsingException(ex);
            }
        }
View Full Code Here

        @Override
        public void source(String systemId) throws Exception {
            try {
                Builder builder = new Builder();
                Document document = builder.build(systemId);
                element = document.getRootElement();
            }
            catch (ParsingException ex) {
                throw new XomParsingException(ex);
            }
        }
View Full Code Here

    private static class StaxStreamConverter {

        private static Document convert(XMLStreamReader streamReader) throws XMLStreamException {
            NodeFactory nodeFactory = new NodeFactory();
            Document document = null;
            Element element = null;
            ParentNode parent = null;
            boolean documentFinished = false;
            while (streamReader.hasNext()) {
                int event = streamReader.next();
                switch (event) {
                    case XMLStreamConstants.START_DOCUMENT:
                        document = nodeFactory.startMakingDocument();
                        parent = document;
                        break;
                    case XMLStreamConstants.END_DOCUMENT:
                        nodeFactory.finishMakingDocument(document);
                        documentFinished = true;
                        break;
                    case XMLStreamConstants.START_ELEMENT:
                        if (document == null) {
                            document = nodeFactory.startMakingDocument();
                            parent = document;
                        }
                        String name = QNameUtils.toQualifiedName(streamReader.getName());
                        if (element == null) {
                            element = nodeFactory.makeRootElement(name, streamReader.getNamespaceURI());
                            document.setRootElement(element);
                        }
                        else {
                            element = nodeFactory.startMakingElement(name, streamReader.getNamespaceURI());
                            parent.appendChild(element);
                        }
View Full Code Here

TOP

Related Classes of nu.xom.Document

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.