Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I realise that Paul's follow up answer pretty much covers your question but I'd just like to add a few more points:</p> <ol> <li>I personally don't like the design of Scala XML, to the extent that I wrote an alternative library <a href="http://code.google.com/p/scala-scales/" rel="nofollow">Scales Xml</a>, but I wouldn't call it badly designed. Design elements of it are apparently also good enough to form the basis of Anti-Xml's approach (Elements owning their children, a concept of grouping nodes etc), but there are many quirks - attribute and text as containers being a large one.</li> <li>I've only recently committed descendant axis to Scales - its greedy nature works differently than descendant-or-self - as per the spec //para<a href="http://code.google.com/p/scala-scales/" rel="nofollow">1</a> does not mean the same as the location path /descendant::para<a href="http://code.google.com/p/scala-scales/" rel="nofollow">1</a></li> <li>I'm not sure you can attribute bad design to Anti-Xml either for its absence, its a young project (just over seven months old?) and they may simply not have gotten round to adding descendant yet.</li> </ol> <p>Direct answer for the attribute question for Scales is:</p> <pre><code>val pre = Namespace("uri:test").prefixed("pre") val elem = Elem("fred"l, emptyAttributes + ("attr", "value") + Attribute(pre("attr"), "value")) println("attributes are a map " + elem.attributes("attr")) println("attributes are a set " + ( elem.attributes + ("attr", "new value"))) val xpath = top(elem) \@ pre("attr") xpath foreach{ap =&gt; println(ap.name)} </code></pre> <p>giving</p> <pre><code>[info] attributes are a map Some(Attribute({}attr,value)) [info] attributes are a set ListSet(Attribute({}attr,new value), Attribute({uri:test}attr,value)) [info] {uri:test}attr </code></pre> <p>The XPath syntax must return a collection as it could be any number of paths that reached a matching attribute. Element Attributes themselves are QName matched "attr" meaning no namespace and localName of attr. For additional sanity an attribute QName is:</p> <pre><code>type AttributeQName = EitherLike[PrefixedQName, NoNamespaceQName] </code></pre> <p>The compiler makes sure no local name only QNames creep in.</p> <p>As an aside, whilst I understand why the Scala XML XPath like syntax is probably uninteresting, you should have a look at Scales for XPath based querying.</p> <p>There is both XPath 1.0 string based querying (not yet pushed into a non snapshot version) and an internal dsl that lets the compiler / ide help you out (plus the bonus of being far quicker and working with scala code directly).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload