src/main/java/org/jboss/loom/utils/XmlUtils.java
public static <T> List<T> unmarshallBeans( File docFile, String xpath, Class<T> cls ) throws MigrationException{
        
        List<T> beans = new LinkedList();
        DocumentBuilder docBuilder = createXmlDocumentBuilder();
        try {
            // Parse
            Document doc = docBuilder.parse(docFile);

            // XPath
            //XPathFactory xpf = XPath xp = XPathFactory.newInstance();
            //XPathFactory xpf = new net.sf.saxon.xpath.XPathFactoryImpl();
            // We need Sun's XPath as it ignores namespaces if not specified.
            //XPathFactory xpf = new com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl(); // Warning
            XPathFactory xpf;
            try {
                xpf = (XPathFactory) Class.forName("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl").newInstance();
            } catch( Exception ex ){ throw new IllegalStateException("Shouldn't happen: " + ex.getMessage(), ex ); }
            
            XPath xp = xpf.newXPath();
            
            NodeList nodes = (NodeList) xp.evaluate(xpath, doc, XPathConstants.NODESET);
            
            
            
            // Unmarshall
            Unmarshaller unmarshaller = JAXBContext.newInstance(cls).createUnmarshaller();
            for( int i = 0; i < nodes.getLength(); i++ ) {
                Node node = nodes.item( i );
                T bean = (T) unmarshaller.unmarshal(node);
                beans.add( bean );
                
                // Origin - set File and XPath.
                if( bean instanceof Origin.Wise ){
                    final Origin orig = new Origin( docFile, xpath ).setOffset( i );
                    ((Origin.Wise) bean).setOrigin( orig );
                }
            }
        }
        catch( SAXException | IOException | XPathExpressionException | JAXBException ex ) {
            throw new MigrationException("Failed parsing bean from a XML file " + docFile.getPath() + ":\n    " + ex.getMessage(), ex);
        }
        return beans;
    }
/**
     *  Read XML from the File, look for nodes by XPath, and unmarshall them into given Class.
     *  If Class is Origin.Wise, the origin is stored.
     * 
     *  Caution: Uses JDK's XPathFactoryImpl - Saxon doesn't do well with namespaces.
     */
Read XML from the File, look for nodes by XPath, and unmarshall them into given Class.
If Class is Origin.Wise, the origin is stored.

Uses JDK's XPathFactoryImpl - Saxon doesn't do well with namespaces.
Read XML from the File look for nodes by XPath and unmarshall them into given Class . If Class is Origin . Wise the origin is stored . Uses JDK ' s XPathFactoryImpl - Saxon doesn ' t do well with namespaces .
public static <T> List<T> unmarshallBeans( File docFile, String xpath, Class<T> cls ) throws MigrationException{
        List<T> beans = new LinkedList();
        DocumentBuilder docBuilder = createXmlDocumentBuilder();
        try {
            Document doc = docBuilder.parse(docFile);
            XPathFactory xpf;
            try {
                xpf = (XPathFactory) Class.forName("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl").newInstance();
            } catch( Exception ex ){ throw new IllegalStateException("Shouldn't happen: " + ex.getMessage(), ex ); }
            XPath xp = xpf.newXPath();
            NodeList nodes = (NodeList) xp.evaluate(xpath, doc, XPathConstants.NODESET);
            Unmarshaller unmarshaller = JAXBContext.newInstance(cls).createUnmarshaller();
            for( int i = 0; i < nodes.getLength(); i++ ) {
                Node node = nodes.item( i );
                T bean = (T) unmarshaller.unmarshal(node);
                beans.add( bean );
                if( bean instanceof Origin.Wise ){
                    final Origin orig = new Origin( docFile, xpath ).setOffset( i );
                    ((Origin.Wise) bean).setOrigin( orig );
                }
            }
        }
        catch( SAXException | IOException | XPathExpressionException | JAXBException ex ) {
            throw new MigrationException("Failed parsing bean from a XML file " + docFile.getPath() + ":\n    " + ex.getMessage(), ex);
        }
        return beans;
    }
public static < T > List < T > unmarshallBeans ( File docFile , String xpath , Class < T > cls ) throws MigrationException { List < T > beans = new LinkedList ( ) ; DocumentBuilder docBuilder = createXmlDocumentBuilder ( ) ; try { Document doc = docBuilder . parse ( docFile ) ; XPathFactory xpf ; try { xpf = ( XPathFactory ) Class . forName ( "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl" ) . newInstance ( ) ; } catch ( Exception ex ) { throw new IllegalStateException ( "Shouldn't happen: " + ex . getMessage ( ) , ex ) ; } XPath xp = xpf . newXPath ( ) ; NodeList nodes = ( NodeList ) xp . evaluate ( xpath , doc , XPathConstants . NODESET ) ; Unmarshaller unmarshaller = JAXBContext . newInstance ( cls ) . createUnmarshaller ( ) ; for ( int i = 0 ; i < nodes . getLength ( ) ; i ++ ) { Node node = nodes . item ( i ) ; T bean = ( T ) unmarshaller . unmarshal ( node ) ; beans . add ( bean ) ; if ( bean instanceof Origin . Wise ) { final Origin orig = new Origin ( docFile , xpath ) . setOffset ( i ) ; ( ( Origin . Wise ) bean ) . setOrigin ( orig ) ; } } } catch ( SAXException | IOException | XPathExpressionException | JAXBException ex ) { throw new MigrationException ( "Failed parsing bean from a XML file " + docFile . getPath ( ) + ":\n    " + ex . getMessage ( ) , ex ) ; } return beans ; }
Read XML from the File, look for nodes by XPath, and unmarshall them into given Class.
Read XML from the File look for nodes by XPath and unmarshall them into given Class .
// Parse // XPath //XPathFactory xpf = XPath xp = XPathFactory.newInstance(); //XPathFactory xpf = new net.sf.saxon.xpath.XPathFactoryImpl(); // We need Sun's XPath as it ignores namespaces if not specified. //XPathFactory xpf = new com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl(); // Warning // Unmarshall // Origin - set File and XPath.