Extracting unprefixed attributes with a default namespace

28 views
Skip to first unread message

efasc...@gmail.com

unread,
May 23, 2013, 7:21:35 AM5/23/13
to scale...@googlegroups.com
Hi all

Let's say I have a namespace
 
  val ns = Namespaces("my.uri") prefixed "myprefix"
  val myElem = ns("elem")
  val myAttr = ns("attr")

And an xml document whose root element defines ns as a default namespace:

  <root xmlns = "my.uri">
    <elem attr="foo"/>
  </root>

Now, when I query this document I find the element (although it is not prefixed) but I don't find the attribute (probably because it is not prefixed):

  doc \* myElem *@ myAttr size == 0

So, how do I extract unprefixed attributes with a prefixed QName when they belong to the default namespace?

Cheers, Stefan

Chris Twiner

unread,
May 25, 2013, 5:31:29 AM5/25/13
to scale...@googlegroups.com
Hi Stefan,

sorry about the delay in response, the work network isn't G friendly,
your probably is correct:

http://stackoverflow.com/questions/3312390/xml-default-namespaces-for-unqualified-attribute-names

has a nice example with reasoning on it. Basically an unprefixed
attribute has no namespace (conceptually its only relevant for the
element anyway).

So to query it you need to have:

scala> val noNSAttr = "attr"l
noNSAttr: scales.xml.NoNamespaceQName = {}attr

scala> doc \* myElem *@ noNSAttr size
res13: Int = 1

to match. Or just inlined:

scala> doc \* myElem *@ "attr" size
res14: Int = 1

Cheers,
Chris
> --
> You received this message because you are subscribed to the Google Groups
> "scales-xml" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scales-xml+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages