How do I remove a node with e4x based on a property? - actionscript

I have a simple example
var myXML:XML =
<root>
<element type="a">I am a</element>
<element type="b">I am b</element>
</root>
;
I cant work out how I can programatically remove an element of a specific type
delete myXML.root.element.type['a'][0];

To remove a XML element by matching an attribute of that element, I believe you're looking for:
var index:int = myXML.element.(#type=="b").childIndex();
delete myXML.element[index];
Based upon your XML:
var myXML:XML =
<root>
<element type="a">I am a</element>
<element type="b">I am b</element>
</root>;
After calling this function, the XML would be:
<root>
<element type="a">I am a</element>
</root>

Related

UI5 List Binding not showing content

I have a list object which is bound to a UI5 List element. However the values are not showing. Please take a look at my code.
UI/xml Code:
<List id="statementList" headerText="Statements"
items="{ path: 'statementListModel>/' }">
<StandardListItem title="{importance}" description="{importance}"/>
</List>
Binding in JS:
var result = JSON.parse(aData.responseData);
that.getView().byId("statementList").setModel(new JSONModel(), "statementListModel");
that.getView().byId("statementList").getModel("statementListModel").setData(result.statementList);
The list object is built like this:
result= {
statementList = [
{
importance = "ASD",
...
},
{
importance = "BDS",
...
}
]
}
However it is just not showing the content. The list has the correct size so the binding somewhat works but the content binding does not work:
Thanks for any help!
You have to add the model name EVERYWHERE:
<StandardListItem title="{statementListModel>importance}" description="{statementListModel>importance}"/>

How can I set a variable from a regular helper method in GSP?

I need to output html where the values depend on what kind of object I have (I'm transitioning between DB representations). Right now I have my logic in a block of g:if expressions. It's relatively difficult to read and debug.
<g:if test="${o.isKindA}">
<g:set var="x" value="${...}" />
<g:set var="y" value="${...}" />
...
</g:if>
<g:else>
<g:set var="x" value="${...}" />
<g:set var="y" value="${...}" />
...
</g:else>
I am particularly not interested in adding these values X and Y as methods of o. What I'd like to do is set them using a view helper, which I understand == "tag lib" in grails:
// Tag Helper
//
class AmazingTagLib {
def valueXFor = { attrs -> o.isKindA? 1 : 2 }
...
}
// The previous GSP, rewritten
//
...
<g:set var="x" value="${ valueXFor(o) }" />
This is failing, however. When I attempt to use x, it is bound to an empty StreamCharBuffer, presumably because I didn't attach anything to out in the implementation of valueXFor. It should have had the integer returned value of my helper.
How can I use such functional helper methods in my view?
The issue is that by default Tag Libraries are used to render to out. In this case you are looking to return an object/value from your method and you need to tell the TagLib that this method is different than the standard behavior. Adding the following will do the trick:
class AmazingTagLib {
static returnObjectForTags = ['valueXFor']
def valueXFor = { attrs -> o.isKindA? 1 : 2 }
...
}

How to dynamically add attribute and value to E4X object in Javascript(Compiled on Rhino)?

I want to create an e4x object.
The I want to dynamically keep adding attributes for it and also add value later.
e.g
var node = <node />;
//some code
1) add attribute to 'node'
2) add value to 'node'
Also I found such examples for Flex3 but none for Javascript. Any further documentation would also be appreciated
if you want to add an attribute or value
var node = <node/>
node.#id = 123
node.toXMLString()
//returns
//<node id="123"/>
if you would like to add attributes named dynamically then use the square brackets
node.#["prioritory"] = "high"
//returns
//<node id="123" prioritory="high"/>
the same works for adding child elements
node.description = "Warning"
node.toXMLString()
//<node id="123" prioritory="high">
// <description>Warning</description>
//</node>
node["location"] = "R23"
node.toXMLString()
//<node id="123" prioritory="high">
// <description>Warning</description>
// <location>R23</location>
//</node>
I find this link helpful when trying to refresh my e4x http://wso2.org/project/mashup/0.2/docs/e4xquickstart.html

Parsing XML with TouchXML, generating docs with children

I'm getting an XML document like this:
<node label = "NAME1" description = "DESCRIPTION1" id = "1">
<node label = "SON1" description = "SONDESCRIPTION1" id = "S1">
<node label = "SON1-1" description = "SONDESCRIPTION1-1" id = "S1-1">
<node label = "SERVICE1" description = "SERVICEDESCRIPTION1" id = "Se1" />
<node label = "SON1-2" description = "SONDESCRIPTION1-2" id = "S1-2">
<node label = "SON2" description = "SONDESCRIPTION2" id = "S2">
....
The idea is that I'm receiving a folder tree with services. I'm thinking in get the XML, and put all the sons in a NSArray, create a new CXMLDocument with the sons and without the root. Then create an NSArray with all the sons and create as many CXMLDocuments as a I need, and again..
My idea is show in a TableView all the sons (SON1, SON2..) and when you touch then you go to other TableView with, in the example of SON1: SON1-1, Service1...
At first I don't know if it is the best way but in case it was I don't know how to create a document with the sons of a node.
Something like this:
while whatever {
NSArray *root = [doc children];
for(CXMLElement *son in root){
doc = new XML Starting in SON1.
}
Anyone knows how implement that?
Thanks.

Groovy AntBuilder, omit conditional attributes, like "setOmitNullAttributes" functionality on MarkupBulder

sample code:
def ant = new AntBuilder()
ant.'antlib:org.jacoco.ant:agent'(
enabled: enabled,
property: 'agentvmparam')
When that "enabled" parameter is null, I'd like it to be not present in the ant task conversion, not merely "empty". "empty" gets evaluated to "true" http://ant.apache.org/manual/develop.html#set-magic which isn't what I want.
xml builder example:
def xml = new MarkupBuilder()
xml.omitNullAttributes = true
xml.root(
requiredAttribute:'required',
optionalAttribute: optionalAttribute
) { }
That "omitNullAttributes" will ensure that the "optionalAttribute" xml element parameter isn't even present if the Groovy parameter evaluates to null.
so I get
<root requiredAttribute='required' />
instead of
<root requiredAttribute='required' optionalAttribute='' />
Bit of a possible workaround, but does this work?
def ant = new AntBuilder()
ant.'antlib:org.jacoco.ant:agent'( [ enabled:enabled,
property:'agentvmparam' ].findAll { it.value != null } )
ie: use a findAll to remove the null entries of the param map

Resources