Sigh. Never mind. Making the Xpath not use the empty prefix worked fine. My mistake was a simple typo in the element name, not the prefix or namespace.
> -----Original Message----- > From: Karr, David > Sent: Tuesday, September 12, 2006 3:36 PM > To: xalan-j-users@xml.apache.org > Subject: RE: XPathAPI: eval exp using nodes with default namespace > > For a self-update, I tried implementing a PrefixResolver > implementation. > This gets me closer, but I'm still having trouble with the > elements I'm using the default namespace for. In this class, > I map the prefix "soapenv" to the SOAP namespace, and the > empty string to my default namespace. With this, expressions > referencing only the "soapenv" prefix work fine. However, > expressions trying to use the default namespace fail with: > > "A node test that matches either NCName:* or QName was > expected." > > Which basically means there was some sort of syntax error. > > I tried a variation of changing the empty prefix to a > non-empty prefix, just in the prefix map and in my xpath > expression (not in the message to parse). This doesn't fail, > it just doesn't match anything :) . > > > -----Original Message----- > > From: Karr, David > > Sent: Tuesday, September 12, 2006 1:10 PM > > To: xalan-j-users@xml.apache.org > > Subject: XPathAPI: eval exp using nodes with default namespace > > > > Xalan 2.7.0, JDK 1.4.2, WebLogic 8.1.4. > > > > I'm trying to write xpath validation expressions for the following > > SOAP message (slightly edited). I could use some help > understanding > > what I'm seeing here, and how to make this work well. > > > > ---------------- > > <?xml version="1.0" encoding="utf-8" standalone="yes"?> > > <soapenv:Envelope > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > > > > xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> > > <soapenv:Body> > > <ReportResponse xmlns="http://..."> > > <ReportUrl>https://.../Test%20Portfolio.csv</ReportUrl> > > <Warnings/><Errors/> > > </ReportResponse> > > </soapenv:Body> > > </soapenv:Envelope> > > ---------------- > > > > I'm processing this with code like this: > > > > ---------------- > > SOAPPart soapPart = message.getSOAPPart(); > > Source xmlSource = soapPart.getContent(); > > TransformerFactory transformerFactory = > > TransformerFactory.newInstance(); > > Transformer transformer = transformerFactory.newTransformer(); > > DOMResult domResult = new DOMResult(); > > transformer.transform(xmlSource, domResult); > > Node node = domResult.getNode(); > > System.out.println("node[" + node + "]"); > > > > Element documentElement = ((Document) node).getDocumentElement(); > > > > for (Iterator iter = xpathStrs.iterator(); iter.hasNext(); ) > > { > > String xpathStr = (String) iter.next(); > > XObject object = XPathAPI.eval(documentElement, xpathStr, node); > > System.out.println("object[" + object + "]"); > > } > > ---------------- > > > > When I evaluate this expression: /soapenv:Envelope > > > > It fails, saying that "soapenv" must resolve to a namespace. > > > > I then tried instead: /env:Envelope > > > > This works (the Xobject is not null). I'm not sure why this works, > > and the other one does not. > > > > Next, I tried the expression: /env:Envelope/env:Body/ReportResponse > > > > This fails. I'm guessing it has something to do with the fact that > > I'm trying to use the default namespace, but I think referencing no > > prefix in Xpath means to use "no namespace", which isn't the same > > thing. > > > > What's going on here, and what do I need to do differently? > > >