create mx Tree from a custom XML - actionscript-3

i have a custom XML, i want to create a mx Tree from that xml, it looks like this one :
<Saa:Header>
<Saa:Message>
<Saa:SenderReference> data
</Saa:SenderReference>
</Saa:Message>
<Saa:Message>
<Saa:SenderReference> data
</Saa:SenderReference>
</Saa:Message>
</Saa:Header>
and
<mx:Tree id="myTreetest"
width="100%"
height="98%"
horizontalCenter="0"
labelField="#label"
/>
the script should be :
myTreetest.dataProvider = new XML(?);

Related

Create XML object with dynamical content from a source CSV file

I have the following CSV file:
iDocType,iDocId,iName,iDate
P,555551555,Braiden,2022-12-31
I,100000001,Dominique,2024-12-10
P,100000002,Joyce,2025-11-15
Using jmeter's JSR223 preprocessor element, I need to compose an XML parent node containing multiple (based on parametrization) child-nodes and each node must contain properties with values of each of these CSV rows.
I think that I need some way to loop over this CSV file and extract values from each row until all of my target objects are composed.
Maybe the approach should be having a method called createMasterXml with 2 arguments like findTargetIdInCsv and targetNumberOfXmlNodes and a for loop inside which parses the csv file and composes child node inside it with the groovy.xml.MarkupBuilder. But I don't know how to approach the problem.
Target logic:
find csv row based on an ID variable
compose the first object with values from the first found row with this ID
find next csv row downwards
compose the 2nd object with values from the 2nd row
.....
do this until the target number of objects are created
if the end of the file is reached start from the top row of the file (without the header)
For example, given the csv file described above:
I get a variable docId populated with the value 100000001 which is found on the 2nd row of data in the csv file (ignoring the header);
I define a variable numberOfNodes = 3;
Then I expect an object created by this mapping:
child node 1 - ValuesFromCsvRow2
child node 2 - ValuesFromCsvRow3
child node 3 - ValuesFromCsvRow1
Update:
JSR223 PreProcessor code:
(Note, with this current approach I am not able to compose the sub-nodes objects based on my intended logic described above, because the current approach does not handle parsing the CSV file and extracting values - I am missing the knowledge to do that)
//input from csv file
docType = vars.get('iDocType').toString()
docId = vars.get('iDocId').toString()
name = vars.get('iName').toString()
date = vars.get('iExpiryDate').toString()
def numberOfNodes = 3
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
xml.nodes() {
createNode(xml, numberOfNodes, 'ID0000')
}
def createNode(builder, repeat, pReqID) {
for (int i = 0 ; i < repeat ; i++) {
builder.object(a:'false', b:'false', pReqID:pReqID +(i+1).toString()) {
builder.al(ad:'2021-09-20', alc:'bla', bla:'2021-09-20T11:00:00.000Z', sn:'AB8912')
builder.doc( docType: docType, docId: docId, name: name , date:date )
}
}
}
def nodeAsText = writer.toString()
//log.info(nodeAsText)
vars.put('passengers3XmlObj', nodeAsText)
The values from the code line with builder.doc is the one which I need to change on each node creation, based on the values from each line in the source csv file.
Currently, in this situation, my master object looks like this, because in each jmeter iteration I know only how to get the values from one row from the csv file, per sampler (using CSV Data Set test plan element):
<objects>
<object a='false' b='false' pReqID='ID00001'>
<al ad='2021-09-20' alc='bla' bla='2021-09-20T11:00:00.000Z' sn='AB8912' />
<doc docType='P' docId='100000001' date='2024-12-10' name='Dominique' />
</object>
<object a='false' b='false' pReqID='ID00002'>
<al ad='2021-09-20' alc='bla' bla='2021-09-20T11:00:00.000Z' sn='AB8912' />
<doc docType='P' docId='100000001' date='2024-12-10' name='Dominique' />
</object>
<object a='false' b='false' pReqID='ID00003'>
<al ad='2021-09-20' alc='bla' bla='2021-09-20T11:00:00.000Z' sn='AB8912' />
<doc docType='P' docId='100000001' date='2024-12-10' name='Dominique' />
</object>
</objects>
But, I need it to look like this, keeping in mid the target logic:
<objects>
<object a='false' b='false' c='ID00001'>
<al ad='2021-09-20' alc='bla' dt='2021-09-20T11:00:00.000Z' sn='AB8912' />
<doc docType='I' docId='100000001' date='2024-12-10' name='Dominique' />
</object>
<object a='false' b='false' c='ID00002'>
<al ad='2021-09-20' alc='bla' dt='2021-09-20T11:00:00.000Z' sn='AB8912' />
<doc docType='P' docId='100000002' date='2025-11-15' name='Joyce' />
</object>
<object a='false' b='false' c='ID00003'>
<al ad='2021-09-20' alc='bla' dt='2021-09-20T11:00:00.000Z' sn='AB8912' />
<doc docType='P' docId='555551555' date='2022-12-31' name='Braiden' />
</object>
</objects>
Can someone please help me achieve this ?
CSV Data Set Config by default reads next line on each iteration of each virtual user. The behaviour is controllable up to certain extend by the Sharing Mode setting but none of the sharing modes is suitable for reading the whole content of the CSV file at once.
If you want to parse all the entries from the CSV file in a single shot - do the reading/parsing in Groovy itself
Something like:
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
def pReqID = 'ID0000'
def lines = new File('test.csv').readLines()
xml.nodes() {
1.upto(lines.size() - 1, { lineNo ->
xml.object(a: 'false', b: 'false', pReqID: pReqID + (lineNo).toString()) {
xml.al(ad: '2021-09-20', alc: 'bla', bla: '2021-09-20T11:00:00.000Z', sn: 'AB8912')
xml.doc(docType: lines.get(lineNo).split(',')[0],
docId: lines.get(lineNo).split(',')[1],
name: lines.get(lineNo).split(',')[2],
date: lines.get(lineNo).split(',')[3])
}
})
}
def nodeAsText = writer.toString()

How to create a custom system field in magento 1?

Magento 1.9
I want to create a new tab in System > Configuration.
In this tab, I need a group tab and in this group tab i want a textarea which is connected to a field of my database. If i edit my textarea, it will modify my database field too.
Look at this: https://prnt.sc/orwph1
I don't know how to connect my textarea with my db.. Create a new tab with a new group it's easy but connect it to the db..
Thanks!
let's assume you want a section that has 2 fields: multiselect, text area. In the multiselect you have all your customer and in the text are you get the modify to apply for a certain db field (related to the customer).
your system.xml should me something like this:
<config>
<tabs>
<admin_customTab_2 translate="label" module="sections">
<label>- TAB NAME -</label>
<sort_order>2</sort_order>
</admin_customTab_2>
</tabs>
<sections>
<customsection2 translate="label" module="sections">
<label>label name</label>
<tab>admin_customTab_2</tab>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<block translate="label">
<label>label name</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<block_customers>
<label>Select user</label>
<comment>user list</comment>
<frontend_type>multiselect</frontend_type>
<backend_model>sections/users</backend_model>
<source_model>sections/users</source_model> <!-- adding a source-model for the form's select -->
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</block_customers>
<block_textarea>
<label>changes to apply</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</block_textarea>
</fields>
</block>
</groups>
</customsection2>
</sections>
this is not enough for the configs, you need to tell Magento about the access control list (ACL) or admin-users will not see it. It is done in the config.xml
like this:
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<customsection2>
<title>Customer Changes?</title>
</customsection2>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
all is setted, but doing nothing but showing us the tabs and forms.
If you was brave enough you noticed a tag in the system.xml code up here,
<backend_model>sections/users</backend_model>
<source_model>sections/users</source_model> <!-- adding a source-model for the form's select -->
this tell magento that you are using a model relating to this form, where you can do operations.
So, in your Model's path create the (in this example) User.php
and here we go:
you want to extend your custom class with this one.
class Admin_Sections_Model_Users extends Mage_Core_Model_Config_Data
yes but we still didn't insert any data in the form.
You can do this by just adding a special function toOptionArray() :
public function toOptionArray()
{
$collections = Mage::getModel("customer/customer")->getCollection();
foreach ($collections as $colletion){
$user = Mage::getModel("customer/customer")->load($colletion->getId());
$array[] = array('value'=>$user->getEntityId(),'label'=>Mage::helper("sections")->__($user->getName()));
}
return $array ;
}
this will set ALL the customer's name into the multi-select form.
"yeah, nice.. I asked about the text-area"
before telling you how to get Data from Store Configs, you should know that there are 2 main methods for elaborating the form data:
public function _afterSave()
{}
public function _beforeSave()
{}
in there you can put all your code, no need to explain what is the difference between them.
in this function you can easy get the Data from Store Config by doing:
$text_area_string = Mage::getStoreConfig('customsection2/block/block_textarea');
"yeah nice... but my main problem is to save things in DB"
you can use whenever you prefer the Mage::getModel('') method , this can connect you to the database. Lets make an example; modify the 'is_active' field on 'customer_entity' table.
$customer = Mage::getModel("customer/customer")->load($customer_id);
$customer->setData("is_active",0);
$customer->save();
this field doesn't do really anything, it is just a very fast example.
This should let you do what you are aiming for.
If something sounds strange, please let me know!

BIML: automatic creation of OleDbDestinations for XMLSource in Dataflow

I'm having a XML file with 2 outputpaths and 2 tables in my staging DB. Tables and outputpaths do have same names.
Instead of writing 2 times OleDbDestination and changing Inputpath and ExternalTableOutput I would like to use some Bimlscript.
My current solution:
<Dataflow Name="DF_MyXml">
<Transformations>
<XmlSource Name="MyXml">
<FileInput ConnectionName="simple.xml" />
<XmlSchemaFileInput ConnectionName="simple.xsd" />
</XmlSource>
<OleDbDestination Name="Database" ConnectionName="Dest">
<InputPath OutputPathName = "MyXml.Database" />
<ExternalTableOutput Table="Database" />
</OleDbDestination>
<OleDbDestination Name="Project" ConnectionName="Dest">
<InputPath OutputPathName = "MyXml.Project" />
<ExternalTableOutput Table="Project" />
</OleDbDestination>
</Transformations>
</Dataflow>
What I would like to achive:
<Dataflow Name="DF_MyXML">
<Transformations>
<XmlSource Name="MyXml">
<FileInput ConnectionName="simple.xml" />
<XmlSchemaFileInput ConnectionName="simple.xsd" />
</XmlSource>
<#foreach (var OutP in ["myXML"].DataflowOutputs) { #>
<OleDbDestination Name="<#=OutP.Name#>" ConnectionName="Dest">
<InputPath OutputPathName = "MyXml.<#=OutP.Name#>" />
<ExternalTableOutput Table="<#=OutP.Name#>" />
</OleDbDestination>
<# } #>
</Transformations>
</Dataflow>
Sadly this isn't working. ;-)
In API-Documentation for AstXMLSourceNode I found the property "DataflowOutputs" which "Gets a collection of all dataflow output paths for this transformation" (sounds promising, uhh?) but I can't even figure out how to reference the XMLSource in Bimlscript in any way.
Starting from RootNode I was able to find my Dataflow-Task but then I got stuck and didn't manage to "find" my Transformations\XMLSource.
Any help would be much appreciated!!
BTW: if there is a solution to automatically create destination-tables based on a given XSD this would be greate too. :-)
You need to make sure your connections are declared in a separate file to be easily accessed in Biml script. You can mess with Console.WriteLine() to print out details about objects to the output window and get a glimpse of what is going on in the BimlScript.
In the second file, traditionally called Environmnet.biml,
you need (only with your xml file connection info, the data here is just a placeholder):
<Connections>
<FileConnection Name="XmlFile" FilePath="C:\test\XmlFile.xml" RelativePath="true" />
<FileConnection Name="XmlXsd" FilePath="C:\test\XmlXsd.Xsd" RelativePath="true" />
</Connections>
then you can do something to the effect of :
var fileConnection = RootNode.Connections["XmlFile"];
(sorry before I accidentally put DbConnections)
and play with it from there. I do not have any xml files at my disposal right now to play around with to help you get the exact information that you are looking for. I will update on Monday.

How to load Nativescript chart properties from json file to xml file?

I want to load the Nativescript (RadCartesianChart) properties from external json file to my main xml file. How to call this RadCartesianChart property from an external json file?
The external json file should look like :
{
"title":"chart",
"chart-type":"Line",
"x-axis":"month",
"y-axis":"amount"
}
This is my current xml file:
<Page
loaded="pageLoaded" class="page"
xmlns="http://www.nativescript.org/tns.xsd"
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:sd="nativescript-pro-ui/sidedrawer"
xmlns:chart="nativescript-pro-ui/chart"
>
<ActionBar title="MyApp" class="action-bar"/>
<StackLayout class="home-panel">
<Label textWrap="true" text="OVERVIEW" class="overview"/>
<Label textWrap="true" text="Sales Report" class="graph-desc"/>
<GridLayout class= "gLayout" rows="*" height="800px" width="1300px">
<chart:RadCartesianChart row="0">
<chart:RadCartesianChart.series class="Line">
<chart:LineSeries items="{{ categoricalSource }}" categoryProperty="{{ categoryProperty }}" valueProperty="{{ valueProperty }}">
<chart:LineSeries.horizontalAxis>
<chart:CategoricalAxis/>
</chart:LineSeries.horizontalAxis>
<chart:LineSeries.verticalAxis>
<chart:LinearAxis/>
</chart:LineSeries.verticalAxis>
</chart:LineSeries>
</chart:RadCartesianChart.series>
</chart:RadCartesianChart>
</GridLayout>
<GridLayout rows="*" xmlns:chart="nativescript-pro-ui/chart" height="800px" width="1300px">
<chart:RadPieChart row="0" allowAnimation="true" row="0">
<chart:RadPieChart.series>
<chart:PieSeries selectionMode="DataPoint" expandRadius="0.4" outerRadiusFactor="0.7" items="{{ categoricalSource }}" valueProperty="Amount"
legendLabel="Department" />
</chart:RadPieChart.series>
<chart:RadPieChart.legend>
<chart:RadLegendView position="Right" title="Dep" offsetOrigin="TopRight" width="110" enableSelection="true" />
</chart:RadPieChart.legend>
</chart:RadPieChart>
</GridLayout>
</StackLayout>
As per https://docs.nativescript.org/core-concepts/data-binding
In your js file add
// Either import your JSON here or...
var OptionsModel = require("./test.json");
// call GetString to get it from server or external source.
// and add it to OptionsModel.
// All the variables you wish to import in the xml add it to pageBinding as an object.
// then you can use {{'options or model or whatever name you give'.'value you want to access inside it'}}
page.bindingContext = {
model: homeViewModel,
options: OptionsModel
};
In your xml add
{{ model.categoricalSource }} or {{options.title}} to access values

Barchsrt series donot show data when I change series name and data provider?

I create my bar chart as following:
{axisStroke}
{axisStroke}
{axisStroke}
<!-- horizontal axis -->
<mx:horizontalAxis>
<mx:LinearAxis id="ac" baseAtZero="true"/>
</mx:horizontalAxis>
<!-- horizontal axis renderer -->
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{ac}"
canDropLabels="true"
styleName="wsViewAxisLabel"
minorTickPlacement="none"
tickPlacement="none"
labelGap="0"
showLabels="false"
showLine="false">
<mx:axisStroke>{axisStroke}</mx:axisStroke>
<mx:tickStroke>{axisStroke}</mx:tickStroke>
<mx:minorTickStroke>{axisStroke}</mx:minorTickStroke>
</mx:AxisRenderer>
</mx:horizontalAxisRenderers>
<mx:series>
<mx:BarSeries id="barSeries" color="#FFFFFF" labelAlign="right"
displayName="{seriesName}"
filters="{[new DropShadowFilter(2,45,0,.3)]}" fontSize="11"
fontWeight="bold" labelField="{valueName}"
xField="{seriesName}"
showDataEffect="{interpolateIn}"
yField="{categoryName}">
<mx:fill>
<mx:LinearGradient id="linearGradient">
<mx:entries>
<fx:Array>
<mx:GradientEntry color="0x99ffcc"
ratio="0.0"
alpha="0.1" />
<mx:GradientEntry color="0x99ffcc"
ratio="1.0"
alpha="1.0"/>
</fx:Array>
</mx:entries>
</mx:LinearGradient>
</mx:fill>
</mx:BarSeries>
</mx:series>
<mx:annotationElements>
<mx:CartesianDataCanvas id="mCanvas"/>
</mx:annotationElements>
</mx:BarChart>
but when I change the series name and datacollection. the bar chart did not show data.
I try to debug code and find the barseries's items length is 0. it's dataprovider and series name, xfield, yfield is right. do not know why barseries did not create barseriesitems.
many thanks for help.
thanks
The dataProvider is bound to the original name, so the dataProvider assignment to the ID needs to be updated. The dataProvider is bound the the ArrayCollection, so the ArrayCollection assignment to the dataProvider needs to be updated as well.
References
Flex Mobile Performance Checklist