Search the web
Sign In
New User? Sign Up
xmlpull-user
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
XPP3 Namespace Use   Message List  
Reply | Forward Message #306 of 308 |
Re: XPP3 Namespace Use

Alek,

Thanks for the quick reply!

I believe that XPP3 is set to be namespace aware, as the factory
method I call to give me an XmlInfosetBuilder object sets this flag
to true for me.

Here is a full Java class that I run. I use the latest XPP3 from the
website link: http://www.extreme.indiana.edu/dist/java-
repository/xpp3/distributions/xpp3-1.1.4c_all.zip

I have extended the XPath functions to include the 'matches' and a
half-implementation of the 'index-of', but I have not touched any of
the underlying "base" code, and I have tested with a non-modified
version to verify.

I still think that I am missing something, probably something
obvious like that setNamespaceAware setter, but I just can't seem to
figure out what.

EG


import java.io.StringReader;
import java.util.ArrayList;

import org.xmlpull.v1.builder.XmlDocument;
import org.xmlpull.v1.builder.XmlInfosetBuilder;
import org.xmlpull.v1.builder.xpath.Xb1XPath;

public class Tester {

/**
* Tester class for quick tests
*
* @param args
*/
public static void main(String[] args) {
String xml = "<ns1:A xmlns:ns1=\"http://some.url.org\">" +
"<ns1:B>" +
"<ns1:C xyz=\"test\"/>" +
"</ns1:B>" +
"</ns1:A>";

try {
XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance();

XmlDocument doc = builder.parseReader(new StringReader(xml));

Xb1XPath predicateObj = new Xb1XPath("/ns1:A/ns1:B");

Object retObj = predicateObj.evaluate(doc);

if (retObj != null) {
System.out.println(retObj.getClass().getName());

if (retObj instanceof ArrayList)
System.out.println(((ArrayList) retObj).size());
} else
System.out.println("null");

} catch (Exception e) {
e.printStackTrace();
}
}
}





--- In xmlpull-user@yahoogroups.com, "Aleksander Slominski"
<aslom@...> wrote:
>
> XPath with namespaces definitely works - i used it many times :)
>
> make sure that XML parsed is with namespace aware builder mdoe set
on?
>
> and if it does nto help please post a full java file that can be
executed to
> reproduce the error including what exactly XXP3 jar file you used.
>
> thanks,
>
> Alek
>
>
> On 10/30/07, lipafrog <lipafrog@...> wrote:
> >
> > Hi all,
> >
> > I am using XPP3 to parse a document containing a custom namespace
> > and use an XPath predicate to pull out an element, but XPP3 does
not
> > find the element! Without the namespace this example works fine,
add
> > the namespace and it returns nothing. Have I failed to use XML
> > namespaces/XPP3 correctly? If so, could someone please point out
how?
> >
> > Thanks!
> > EG
> >
> > The XML is like:
> > <ns1:A xmlns:ns1="http://some.url.org">
> > <ns1:B>
> > <ns1:C xyz="test"/>
> > </ns1:B>
> > </ns1:A>
> >
> > The code I try to use looks like, and returns an empty ArrayList:
> > Xb1XPath predicateObj = new Xb1XPath("/ns1:A/ns1:B");
> >
> > Object retObj = predicateObj.evaluate(docObj);
> >
> > if (retObj != null) {
> > System.out.println(retObj.getClass().getName());
> >
> > if (retObj instanceof ArrayList) {
> > System.out.println(((ArrayList) retObj).size());
> > }
> > } else
> > System.out.println("null");
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>
> --
> ---
> The best way to predict the future is to invent it - Alan Kay
>





Fri Nov 2, 2007 11:38 am

lipafrog
Offline Offline
Send Email Send Email

Forward
Message #306 of 308 |
Expand Messages Author Sort by Date

Hi all, I am using XPP3 to parse a document containing a custom namespace and use an XPath predicate to pull out an element, but XPP3 does not find the...
lipafrog
Offline Send Email
Oct 30, 2007
6:15 pm

XPath with namespaces definitely works - i used it many times :) make sure that XML parsed is with namespace aware builder mdoe set on? and if it does nto help...
Aleksander Slominski
as10m
Offline Send Email
Oct 30, 2007
6:25 pm

Alek, Thanks for the quick reply! I believe that XPP3 is set to be namespace aware, as the factory method I call to give me an XmlInfosetBuilder object sets...
lipafrog
Offline Send Email
Nov 2, 2007
5:08 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help