xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Radu Preotiuc <radu.preotiuc-pie...@oracle.com>
Subject Re: simple example not working
Date Mon, 18 May 2009 18:03:13 GMT
When you used XmlOptions.setLoadSubstituteNamespaces(), the elements
have been "moved" to the "http://xml.report.nexpose.rapid7.net"
namespace.

Try instead

XmlObject.selectChildren(new
QName("http://xml.report.nexpose.rapid7.net", "scan")

HTH,
Radu

On Mon, 2009-05-18 at 18:17 +0100, David McReynolds wrote:
> I was using jaxb for my xml needs but it was proving to slow.
> 
> However, I am confounded by this simple example. I have the XSD for a
> NexposeReport as released by Rapid7 and I have successfully generated
> the beans using Ant. I had to add a couple of namespace declarations to
> the Rapid7 XSD.
> 
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns="http://xml.report.nexpose.rapid7.net"
> targetNamespace="http://xml.report.nexpose.rapid7.net">
> 
> 
> These are my "made up" namespace values since the original had no
> mention of a namespace.
> 
> The parser complained about the lack of a namespace in the xml instance.
> 
> <NexposeReport version="1.0">
> <scans>
> <scan> . . . 
> 
> So, I added a subtitution.
> 
> Map<String,String> substNamespaces = new HashMap<String,String>();
> substNamespaces.put("", "http://xml.report.nexpose.rapid7.net");
> xmlOps.setLoadSubstituteNamespaces(substNamespaces);
> reportDoc = NexposeReportDocument.Factory.parse(sr,xmlOps);
> 
> However, I cannot figure out how to select all the scan nodes from the
> xml instance.
> 
> @Test
> public void loadReport() throws Exception {
> 	NexposeReportDocument reportDoc = null;
> 
> 	boolean hasResults = false;
> 	for(int i = 1; i < RPT_IDX_MAX; i++) {
> 		String fname = RPT_BASE_NAME + i + ".xml";
> 		InputStream ios  = new FileInputStream(fname);
> 		XMLStreamReader sr = new XMLStreamReader(ios,false);
> 		XmlOptions xmlOps = new XmlOptions();
> 		Map<String,String> substNamespaces = new HashMap<String,String>();
> substNamespaces.put("","http://xml.report.nexpose.rapid7.net");			
> 	xmlOps.setLoadSubstituteNamespaces(substNamespaces);
> 	reportDoc = NexposeReportDocument.Factory.parse(sr,xmlOps);
> 	XmlCursor xmlCursor = reportDoc.newCursor();
> 			xmlCursor.selectPath("$this//NexposeReport/scans/scan");
> 	System.out.println("# of selections: " +
> xmlCursor.getSelectionCount());
> 	xmlCursor.dump();
> 	while (xmlCursor.toNextSelection()) {
> 				System.out.println(xmlCursor.getTextValue());
> 		}
> 	}
> }
> 
> The output:
> 
> # of selections: 0
>   ROOT (USER) *:R:<cur>[0] <mark>[0] (DocumentXobj)
>     ELEM NexposeReport@http://xml.report.nexpose.rapid7.net
> (ElementXobj)
>       ATTR version Value( "1.0" ) After( "\n" ) (AttrXobj)
>       ELEM scans@http://xml.report.nexpose.rapid7.net Value( "\n" )
> (ElementXobj)
>         ELEM scan@http://xml.report.nexpose.rapid7.net After( "\n" )
> (ElementXobj)
>           ATTR id Value( "130" ) (AttrXobj)
>           ATTR name Value( "3592" ) (AttrXobj)
>           ATTR startTime Value( "20090324T170449013" ) (AttrXobj)
>           ATTR endTime Value( "20090324T171328716" ) (AttrXobj)
>           ATTR status Value( "finished" ) (AttrXobj)
> 
> <snip>lots more data</snip>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Mime
View raw message