Return-Path: Delivered-To: apmail-xmlbeans-user-archive@www.apache.org Received: (qmail 22972 invoked from network); 18 May 2009 18:05:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 May 2009 18:05:11 -0000 Received: (qmail 27726 invoked by uid 500); 18 May 2009 18:05:11 -0000 Delivered-To: apmail-xmlbeans-user-archive@xmlbeans.apache.org Received: (qmail 27705 invoked by uid 500); 18 May 2009 18:05:11 -0000 Mailing-List: contact user-help@xmlbeans.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: user@xmlbeans.apache.org List-Id: Delivered-To: mailing list user@xmlbeans.apache.org Received: (qmail 27697 invoked by uid 99); 18 May 2009 18:05:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 18:05:11 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [148.87.113.124] (HELO rgminet12.oracle.com) (148.87.113.124) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 18:05:01 +0000 Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rgminet12.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n4II4Upp028689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 18 May 2009 18:04:31 GMT Received: from abhmt001.oracle.com (abhmt001.oracle.com [141.146.116.10]) by acsinet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n4II5Ddr013614 for ; Mon, 18 May 2009 18:05:13 GMT Received: from [10.137.151.2] (/10.137.151.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 18 May 2009 11:04:35 -0700 Subject: Re: simple example not working From: Radu Preotiuc To: user@xmlbeans.apache.org In-Reply-To: <1242667047.31393.16.camel@dmcreynolds-ubuntu> References: <1242667047.31393.16.camel@dmcreynolds-ubuntu> Content-Type: text/plain Date: Mon, 18 May 2009 14:03:13 -0400 Message-Id: <1242669793.2877.44.camel@radup02> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 (2.22.3.1-1.fc9) Content-Transfer-Encoding: 7bit X-Source-IP: abhmt001.oracle.com [141.146.116.10] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A09020B.4A11A334.011A:SCFSTAT5015188,ss=1,fgs=0 X-Virus-Checked: Checked by ClamAV on apache.org 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. > > 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. > > > > . . . > > So, I added a subtitution. > > Map substNamespaces = new HashMap(); > 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 substNamespaces = new HashMap(); > 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:[0] [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) > > lots more data > > > --------------------------------------------------------------------- > 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