Thanks. That was the problem. I just removed my "made up" namespace,
regenerated and it started working.

On Mon, 2009-05-18 at 14:03 -0400, Radu Preotiuc wrote:
> 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 nexposerep...@http://xml.report.nexpose.rapid7.net
> > (ElementXobj)
> >       ATTR version Value( "1.0" ) After( "\n" ) (AttrXobj)
> >       ELEM sc...@http://xml.report.nexpose.rapid7.net Value( "\n" )
> > (ElementXobj)
> >         ELEM s...@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: [email protected]
> > For additional commands, e-mail: [email protected]
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to