Hi, Ben.
I went away for a week and came
back to 800 flexcoders messages. I've been trying to understand the
basic problem in this thead, which seems to have drifted away from the
essential problem.
You started with XML
like
var entries:XML =
<rootNode
xmlns="http://site.com/Back/DocMetadata">
<Entry>
<CreateDate>5/5/2006
9:56:30
AM</CreateDate>
<DocumentType>RPR</DocumentType>
</Entry>
<Entry>
<CreateDate>5/3/2006
3:07:27
PM</CreateDate>
<DocumentType>RPR</DocumentType>
</Entry>
</rootNode>;
You discovered that when you use
this as the data provider for a DataGrid, the simple specification of
labelField="CreateDate" doesn't work because there are namespaces involved. As
Tobias Patton pointed out, the workaround is to use a labelFunction that
accesses the <CreateDate> elements as
XML(item).ns::CreateDate
where
var ns:Namespace =
new
Namespace("http://site.com/Back/DocMetadata");
By the way, you don't need to
hard-code the namespace. As Geoffrey Williams pointed out in another thread on
6/8, you can get at the default namespace as
var
ns:Namespace = entries.namespace("");
I don't recommend trying to "strip
out" the namespace, simply in order to use labelField. That seems like bad
practice as it wouldn't work with more complicated XML that actually relies on
namespaces to disambiguate XML elements with the same unqualified name. (I
also don't know the right way to strip it out and haven't investigated the
problems you're having doing so.)
Perhaps in a future version of
Flex we can generalize labelField to be a QName rather than a String, and
support something like labelField="{ns::CreateDate}".
- Gordon
>
What's the value of
> entries.namespaceDeclarations()
?
> --
> Tom Chiverton
OK, now I am even more confused :).
Turns out that for my simple
example (defining a small XML var inside the
MXML file), the default
namespace is in fact included in the array returned
by
namespaceDeclarations(). However, if I create a new XML var from
a
subset of my SOAP response and then try to get the default
namespace
data, it doesn't work.:
var x:XML = new
XML(event.message.body);
namespace d = "http://site.com/Back/DocMetadata";
use
namespace d;
var x2:XML = new
XML(x..Metadata);
x2.namespaceDeclarations().length; //
returns 0
x2.namespaceDeclarations().toString(); //returns
this:
<Metadata xmlns="http://site.com/Back/DocMetadata">
<RPRDocumentHistory>
<MetadataType>RPRDocumentHistory</MetadataType>
</RPRDocumentHistory>
</Metadata>