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

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

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
Re: [xmlpull-dev] XmlPullParser.getAttributeValue( )   Message List  
Reply | Forward Message #37 of 308 |
Naresh Bhatia wrote:

> I need some clarification on
> XmlPullParser.getAttributeValue(java.lang.String namespace,
> java.lang.String name). My schema is as follows:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
> targetNamespace="http://www.user.org/user-schema"
> xmlns="http://www.user.org/user-schema"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
>
> <xsd:complexType name="User">
> <xsd:sequence>
> <xsd:attribute name="username" type="xsd:string"/>
> <xsd:attribute name="password" type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
>
you have selected |unqualified for attribute names and that means that
|locally declared must be unqualified ie. without targetNamespace AFAIR

> <xsd:element name="user" type="User"/>
> </xsd:schema>
>
> My instance is as follows:
>
> <user
> xmlns="http://www.user.org/user-schema"
> username="john" password="john"/>
>
> I was expecting to get the username attribute as follows:
>
> parser.getAttributeValue("http://www.user.org/user-schema",
> "username");
>
> However xpp3 did not like the namespace parameter: I set it to null
> and even that did not work. Finally it worked with the following change:
>
> parser.getAttributeValue("", "username");
>
> Is this the expected behavior?
>
yes as you have attributes form defaulted to unqualified so there is no
namespace.

> Why?
>
if you want attributes to be present in some namespace you need to
explicitly declare them in that namespaces as xmlns='...' does not apply
to attributes: checking Namespaces in XML
(http://www.w3.org/TR/REC-xml-names/) reading section 5.2 Namespace
Defaulting "Note that default namespaces do not apply directly to
attributes."

as solution rewrite your XML to not use default namespace so attributes
can be declared in namespaces:

<u:user
xmlns:u="http://www.user.org/user-schema"
u:username="john" u:password="john"/>


and you will get results you expect.

HTH

alek





Tue Mar 4, 2003 8:49 pm

as10m
Offline Offline
Send Email Send Email

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

... you have selected |unqualified for attribute names and that means that ... yes as you have attributes form defaulted to unqualified so there is no ...
Aleksander Slominski
as10m
Offline Send Email
Mar 4, 2003
8:50 pm
Advanced

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