Flex e4x filter out children - apache-flex

I'm trying to filter my xml so that the childnodes are not displayed.
This xml will then be used as a dataprovider for my advanceddatagrid.
Given this XML :
<item text="folder1" display="true">
<item text="folder2" display="true">
<item text="node" display="true">
<item display="false">
<property1>val1</property1>
<property2>val2</property2>
</item>
</item>
</item>
</item>
What I want is an XML with only the nodes that have the property display set to true.
So, the resulting XML should be:
<item text="folder1" display="true">
<item text="folder2" display="true">
<item text="node" display="true">
</item>
</item>
</item>
When I try trace(data.item.(#display == 'true')); every node is still displayed, even the ones with display false..
Any help would be appreciated ..

okay, this is how I solved it now :
var childNodes:XMLList = new XMLList(data.descendants("item").(#display == 'false'));
for ( var i:int = childNodes.length() - 1; i >= 0; i-- ) {
delete childNodes[i];
}

I think this is happening because of the format of that XML.
All of the item elements under folder1 are child nodes of folder1. Since it has
display="true", then the trace will display all of its children.
Anyone else, is this XML formatted correctly to do the search?

Related

XQuery produces incorrect output

The example xml looks like this:
<sales>
............
<customer custid="108">
<name>NORTH WOODS HEALTH AND FITNESS SUPPLY CENTER</name>
<address>98 LONE PINE WAY</address>
<city>HIBBING</city>
<state>MN</state>
<zip>55649</zip>
<area>612</area>
<phone>566-9123</phone>
<repid>7844</repid>
<creditlimit>8000</creditlimit>
<ord ordid="613">
<orderdate>1987-02-01</orderdate>
<shipdate>1987-02-01</shipdate>
<total>6400</total>
<item itemid="1">
<product_ref ref="100871"/>
<actualprice>5.6</actualprice>
<qty>100</qty>
<itemtot>560</itemtot>
</item>
</ord>
</customer>
<product prodid="100860">
<descrip>ACE TENNIS RACKET I</descrip>
<price>
<stdprice>35</stdprice>
<minprice>28</minprice>
<startdate>1986-06-01</startdate>
</price>
</product>
.........
</sales>
let $product := doc('sales.xml')/sales/product
for $item in doc('sales.xml')/sales/customer/ord/item
where $item/actualprice < $product[#prodid=$item/product_ref/#ref]/price/minprice
return $item
And I get as result this:
<item itemid="1">
<product_ref ref="100861"/>
<actualprice>35</actualprice>
<qty>1</qty>
<itemtot>35</itemtot>
</item>
<item itemid="3">
<product_ref ref="101863"/>
<actualprice>10</actualprice>
<qty>150</qty>
<itemtot>1500</itemtot>
</item>
<item itemid="7">
<product_ref ref="101863"/>
<actualprice>12.5</actualprice>
<qty>200</qty>
<itemtot>2500</itemtot>
</item>
<item itemid="5">
<product_ref ref="101863"/>
<actualprice>9</actualprice>
<qty>100</qty>
<itemtot>900</itemtot>
</item>
But the items with ref=101863 are not right. Only the item with id=5 is less then minprice.
Why does this error occur? Tried a lot of different queries but it gives me always the same result.
It works fine with ref=100861.
Assuming the query isn't schema-aware, you are comparing the two prices as strings, not as numbers. You need to convert both to numbers before comparison.

XQuery: Return value of attribute if it contains another spesific attribute

I want to return a result on all the books which contain the "databases" attribute in inside of "field".
for $e in //testbook[field="databases"]
return $e/title
Sample of the .xml file:
<?xml version="1.0" encoding="UTF-?>
<testbook>
<book>
<author> AuthorGuy </author>
<title> theBook</title>
<field> databases </field>
</book>
</testbook>
There are two issues:
<title/> and <field/> elements are contained in a <book/> element, and are not direct children of <testbook/>, fix the path expressions.
The <field/> tag contains the field wrapped in whitespace, use contains($string, $needle) instead of a simple comparison.
A working example:
let $document := document{<testbook>
<book>
<author> AuthorGuy </author>
<title> theBook</title>
<field> databases </field>
</book>
</testbook>}
for $e in $document//testbook[contains(book/field, "databases")]
return $e/book/title

Create a XML file having a particular schema using Xquery

I am new to Xquery, I want to change the given xml into another xml format.
Given XML:
<?xml version="1.0" encoding="UTF-8"?>
<Store>
<consumer id="H01">
<name>John Doe</name>
<items>
<item type = "Torch">
<price>$3</price>
</item>
<item type = "Gas">
<price>$4</price>
</item>
</items>
</consumer >
<consumer id="H05">
<name>Jane Doe</name>
<items>
<item type = "Cell">
<price>$8</price>
</item>
<item type = "Shirt">
<price>$12</price>
</item>
</items>
</consumer>
Desired XML Format:
<Store>
<user>
<number><id>H01</id><name>John Doe</name></number>
<number><id>H05</id><name>Jane Doe</name></number>
</user>
<inventory>
<number><type>Torch</type><price>$3</price></number>
<number><type>Gas</type><price>$4</price></number>
<number><type>Cell</type><price>$8</price></number>
<number><type>Shirt</type><price>$12</price></number>
</inventory>
</Store>
Xquery I made:
for $customer in distinct-values(doc("../xml/store.xml")/store/consumer/#id)
let $name := doc("../xml/store.xml")/store/consumer[#id=$customer]/name
for $object in distinct- values(doc("../xml/store.xml")/store/consumer[#id=$customer]/items/item/#type)
return
<store>
<user>
<number>
<id>{$customer}</id>
{$name}
</number>
</user>
<inventory>
<number>
<type>{$object}</type>
</number>
</inventory>
</store>
Where exactly am I going wrong? Is there a way we could make attributes as new node elements.
your two for clauses are nested, you don't want that in this case. I would do something like this:
let $doc := doc("../xml/store.xml")
let $customerIds := distinct-values($doc/store/consumer/#id)
return
<store>
<user>{for $customerId in $customerIds
let $consumer := $doc/store/consumer[#id=$customerId]
return <number><id>{data($consumer/#id)}</id><name>{$consumer/name}</name></number>
}
</user>
<inventory>
similar thing for items
</inventory>
</store>
Is there a way we could make attributes as new node elements.
Yes you can for example use the data() function to extract the text. See example above.

Is there an easy way to get a textual representation of a GtkWidgetPath?

I haven't found any *_to_string() function for GtkWidgetPath, so how can I examine its content easily to debug an issue I'm having? Printing its text representation on the console would be grand.
If i understand you correct you want to put something like
<Widget>#<Name>: <NameOfObject>#<Name>
The widget belongs to the following style classes: <listOfClasses>
Complete Path: <Path>
for a specific widget on the screen.
I wrote the following two functions that do the job. The code should be easily translatable into other languages and is self explanatory if you have the reference at hand.
gchar *
widget_path_get_style_classes (GtkWidgetPath * path)
{
GSList *list;
gchar *str = NULL, *ptr;
list = gtk_widget_path_iter_list_classes (path, -1);
if (list == NULL)
return NULL;
do {
ptr = str;
str = g_strdup_printf (".%s", (gchar *) list->data);
str = g_strjoin (", ", str, ptr, NULL);
g_free (ptr);
} while (list = g_slist_next (list));
g_slist_free(list);
return str;
}
void
widget_path_dumper (GtkWidget * widget)
{
GtkWidgetPath *path;
guint i, length;
gchar *str;
GType type;
path = gtk_widget_get_path (widget);
length = gtk_widget_path_length (path) - 1;
type = gtk_widget_path_iter_get_object_type (path, length);
str = (gchar *) gtk_widget_path_iter_get_name (path, length);
if (str != NULL)
g_print ("<Widget>#<Name>: %s#%s\n", g_type_name (type), str);
else
g_print("<Widget>: %s\n", g_type_name(type));
str = widget_path_get_style_classes (path);
if (str != NULL) {
g_print
("\tThe widget belongs to the following style classes: %s\n", str);
g_free (str);
}
g_print ("\tComplete Path: ");
for (i = 0; i <= length; i++) {
type = gtk_widget_path_iter_get_object_type (path, i);
g_print ("/%s", g_type_name (type));
}
g_print ("\n");
}
Example:
If you call widget_path_dumper on the instantiated button1 widget of the attached ui file it puts
<Widget>#<Name>: GtkButton#myspecialbutton
The widget belongs to the following style classes: .button
Complete Path: /GtkWindow/GtkGrid/GtkFrame/GtkAlignment/GtkButton
on the screen.
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="border_width">10</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">10</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="left_padding">12</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="name">myspecialbutton</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="use_action_appearance">False</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes"><b>frame1</b></property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Since gtk v3.2 there is gtk_widget_path_to_string, which can be used simple like that:
printf("%s\n",gtk_widget_path_to_string (path));
.. however the output is not that nice looking compared to user1146332's proposal

Voicexml how to store input into a global variable

I'm creating a voicexml appliacation.
I want to store an user input into a global variable.
I wondered, the input should be stored in the fieldvar. shouldn't it? After I tried it with this, i tried to store it in an global variable:
<assign name="myvar" expr="'myinput'"/>
but somehow it didn't work. I used value expr="var" as expr.
<?xml version="1.0" encoding="UTF-8"?>
<vxml xmlns="http://www.w3.org/2001/vxml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/vxml
http://www.w3.org/TR/voicexml20/vxml.xsd"
version="2.0">
<var name="myProdukt" />
<form id="test">
<field name="var">
<prompt bargein="true" bargeintype="hotword" >Sagen Sie ein Produkt</prompt>
<grammar root="main" version="1.0" xml:lang="de-DE">
<rule id="main" scope="public">
<one-of>
<item> p1 </item>
<item> p2 </item>
<item> p3 </item>
<item> p4 </item>
</one-of>
</rule>
</grammar>
<filled>
<assign name="myProdukt" expr="<value expr="var"/>"/>
</filled>
</field>
</form>
<<!--[...] Here i want to use the input.-->
</vxml>
thanks in advance
---------------EDIT:
now i used this:
<filled>
test
<assign name="myProdukt" expr="var" />
</filled>
I only changed that. The Applications says "test" but then there is an error.
It isn'T allowed to use "var" instead I used an other name :-)
Did you try a simple assignment of field var to the variable myProdukt like so ?
<filled>
<assign name="myProdukt" expr="var"/>
</filled>
Which would be fine except that according to Section 5.1, Variables and Expressions of the Voice XML specification:
VoiceXML variables, including form
item variables, must not contain
ECMAScript reserved words.
So, you'll need to rename the field var to something that is not a reserved word in ECMAscript, say productSelection:
<field name="productSelection">
<!-- .. prompt, grammar as before .. -->
<filled>
<assign name="myProdukt" expr="productSelection"/>
</filled>
</field>

Resources