Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

DataSource: How to get attributes from identical tags

$
0
0
SmartGWT version: v9.1p_2014-06-14/LGPL
Browser: Firefox v2.4

Hi there!

I have a problem to get different attributes from identical tags for my datasource from XML.
I know, the problem has be discussed a lot of time, but I just don't get how to use the nested datasources therefore.

I have a XML in this form:
Code:

<feed>
  <entry>
    <id>1234</id>
    <content>Lorem Ipsum</content>
    <category term="Level X"/>
    <category term="Type Y"/>
  </entry>
</feed>

What I have tried so far:
Code:

DataSource ds = new DataSource(urlOfXml);
ds.setDataFormat(DSDataFormat.XML);
ds.setRecordXPath("/feed/entry");

DataSourceTextField id = new DataSourceTextField("id");               
id.setValueXPath("./id");
id.setPrimaryKey(true);

DataSourceTextField content = new DataSourceTextField("content");
content.setValueXPath("./content");

DataSourceEnumField category = new DataSourceEnumField("category");                       
category.setValueXPath(".//category/@term"); *
category.setMultiple(true);

ds.setFields(id, content, category);

* should be a valid XPath syntax to get all category tags' term-attributes.
But only the first one is always fetched. ("Level X");
I've seen that the "setMultiple(true)" would work with actual VALUES of tags, but it doesn't with attributes..
It would work with two category-Fields and
Code:

category1.setValueXPath("./category[1]/@term");
category2.setValueXPath("./category[2]/@term");

but I can not be sure, that the ordering of Type and Level is always the same.

One record should be one row in a ListGrid.

| ID | CONTENT | LEVEL | TYPE

Could please somebody give me a concrete code snippet how to fix this with a second datasource?
Or have i overseen something?

Thanks in advance!

Viewing all articles
Browse latest Browse all 4756

Trending Articles