Expand my Community achievements bar.

SOLVED

Accessing XML Data File

Avatar

Level 1
Ok I need a quick lesson on accessing various tags in a xml
file and displaying them. I have a rather messy xml file that
dynamically created and the structure cannot be changed due to an
Excel application that is already accessing it.




Here's the xml:


<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<Files>

<active>

<record>

<sendto>Joe D</sendto>

<head>

<level1>

<submited>true</submited>

<name>MIKE B</name>

<str>1</str>

<date>7/18/2006</date>

<notes>get this loaded!!!!!!!!!!!!!!!!!</notes>

</level1>

<level2>

<submited>false</submited>

<name></name>

<str></str>

<date></date>

<notes></notes>

</level2>

<level3>

<submited>false</submited>

<name></name>

<str></str>

<date></date>

<notes></notes>

</level3>

<level4>

<submited>false</submited>

<name></name>

<str></str>

<date></date>

<notes></notes>

</level4>

</head>

<itemcd>1234567</itemcd>

<desc>TEST</desc>

<retail>5</retail>

<aisle>AA01</aisle>

<replcst>2</replcst>

<pack>1</pack>

<upc>123456789999</upc>

<vendor>EMRYW</vendor>

<venditemcd>1234567</venditemcd>

<grp>2</grp>

<sec></sec>

<insaft></insaft>

<sellum default="each"></sellum>

<fracu default="i"></fracu>

<decp default="0"></decp>

<allowfr default=" "></allowfr>

<prium default="each"></prium>

<selluf default="1.00000"></selluf>

<priscal default="1"></priscal>

<stockum default="each"></stockum>

<itemstyp default="0"></itemstyp>

<traqoh default="y"></traqoh>

<rcvum default="each"></rcvum>

<rcvuf default="1.00000"></rcvuf>

<rcvscal default="1"></rcvscal>

<shipum default="each"></shipum>

<shipuf default="1.00000"></shipuf>

<stockingstr>

<str1>true</str1>

<str2>false</str2>

<str3>false</str3>

</stockingstr>

<pricematlev default="0"></pricematlev>

<qbreaktable default="0"></qbreaktable>

<taxflg default="y"></taxflg>

<gstcd default="0"></gstcd>

<tradedisf default="n"></tradedisf>

<promptpayf default="y"></promptpayf>

<commflg default="y"></commflg>

<additdescf default="n"></additdescf>

<talleyitemf default="n"></talleyitemf>

<nonstkitem default="n"></nonstkitem>

<assemblyitemf default="n"></assemblyitemf>

<assemblyitemtype
default="0"></assemblyitemtype>

<assemblyledtm default="0"></assemblyledtm>

<assemblywrkuts default="n/a"></assemblywrkuts>

<billmattyp default="0"></billmattyp>

<serialnumf default="n"></serialnumf>

<bascomitemf default="n"></bascomitemf>

<bascomitemcd></bascomitemcd>

<lotctrlf default="n"></lotctrlf>

<lotctrlnum default="0"></lotctrlnum>

<relitemmsgnum default="0"></relitemmsgnum>

<hazmatnum default="0"></hazmatnum>

<strydf default="s"></strydf>

<keyitemf default="n"></keyitemf>

<ctrlitemf default="n"></ctrlitemf>

<talleyindiv></talleyindiv>

<textfld2></textfld2>

<numfld1 default="0"></numfld1>

<numfld2 default="0"></numfld2>

<glacctcd default=""></glacctcd>

<stkitemrptf default="y"></stkitemrptf>

<lifopolnum default="0"></lifopolnum>

<lifosampf default="n"></lifosampf>

<pricetabname default=""></pricetabname>

<invcstperc default="0.00">

<str1></str1>

<str2></str2>

<str3></str3>

</invcstperc>

<invcritfac
default="0.00"><str1></str1><str2></str2><str3></str3></invcritfac>

<invglnum
default="0"><str1></str1><str2></str2><str3></str3></invglnum>

<invlngrngfac
default="0.00"><str1></str1><str2></str2><str3></str3></invlngrngfac>

<invminq default="1">

<str1></str1>

<str2></str2>

<str3></str3>

</invminq>

<invmaxq default="2">

<str1></str1>

<str2></str2>

<str3></str3>

</invmaxq>

<minmaxtab default="DO_NOT_ORDER">

<str1></str1>

<str2></str2>

<str3></str3>

</minmaxtab>

<invmingpperc default="49">

<str1></str1>

<str2></str2>

<str3></str3>

</invmingpperc>

<invordq
default="0"><str1></str1><str2></str2><str3></str3></invordq>


<price1><str1></str1><str2></str2><str3></str3></price1>


<price2><str1></str1><str2></str2><str3></str3></price2>


<price3><str1></str1><str2></str2><str3></str3></price3>


<price4><str1></str1><str2></str2><str3></str3></price4>


<price5><str1></str1><str2></str2><str3></str3></price5>


<price6><str1></str1><str2></str2><str3></str3></price6>


<price7><str1></str1><str2></str2><str3></str3></price7>


<price8><str1></str1><str2></str2><str3></str3></price8>

<aisle default="XXXXX">

<str1>AA01</str1>

<str2></str2>

<str3></str3>

</aisle>


<bin><str1></str1><str2></str2><str3></str3></bin>


<shelf><str1></str1><str2></str2><str3></str3></shelf>


<invstdcst><str1></str1><str2></str2><str3></str3></invstdcst>


<manminmax><str1></str1><str2></str2><str3></str3></manminmax>


<text2><str1></str1><str2></str2><str3></str3></text2>


<numer1><str1></str1><str2></str2><str3></str3></numer1>


<numer2><str1></str1><str2></str2><str3></str3></numer2>

<keyword default=""></keyword>

<note default="">get this
loaded!!!!!!!!!!!!!!!!!</note>

</record>

</active>

</Files>







Here's the code I have so far:


<?xml version="1.0" encoding="utf-8"?>

<Application xmlns="
http://www.adobe.com/2006/mxml"
layout="absolute" xmlns:local="*">

<XML id="feedData" source="index.xml"/>

<DataGrid dataProvider="{feedData..active.record}"
x="324" y="138" width="500">

<columns>

<DataGridColumn id="SubmittedBy" headerText="Submitted
By" dataField=""/>

<DataGridColumn headerText="Item" dataField="itemcd"/>

<DataGridColumn headerText="Description"
dataField="desc"/>

</columns>

</DataGrid>

</Application>




What I want to know is how to access and put into the "
Submitted By" column
<Files><active><record><head><level1><name>



Any help would be great since I'm stuck.
1 Accepted Solution

Avatar

Correct answer by
Level 1
After a little digging and a couple cups of coffee, I managed
to pull some data extracting from xml into a datagrid. I can access
attributes, node values, etc...



One thing I did notice, is that you have to refresh the
application if you have dynamic data constantly being updated. So
here is some code to help some of you out:





First some sample XML (index.xml):





<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<records>

<active name="John" id="1234" location="New York">

<job>Architect</job>

<address>111 Salisbury Rd</address>

</active>



<inactive name="Chris" id="5432" location="California">

<job>Web Designer</job>

<address>888 Orchard Rd</address>

</inactive>



</records>








Code with two tabs one name (
Active), other named (
Inactive):






<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" xmlns:local="*" pageTitle="Test App"
creationComplete="srv.send()">



<mx:HTTPService id="srv" url="
http://www.domain.com/index.xml?rand=math.random();"
resultFormat="e4x" useProxy="false" showBusyCursor="true" />

<mx:XMLListCollection id="xActive"
source="{srv.lastResult.active}" />

<mx:XMLListCollection id="xInActive"
source="{srv.lastResult.inactive}" />



<mx:script>

<[[

private function RefreshData():void{

xActive.refresh();

xInActive.refresh();

}

]]>

</mx:Script>



<mx:TabNavigator>

<mx:Canvas label="Active" width="100%" height="100%"
id="canvas1" initialize="RefreshData();">

<mx:DataGrid id="activeData" dataProvider="{xActive}"
selectedIndex="0" editable="true" enabled="true">

<mx:columns>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@name" headerText="Name"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@id" headerText="ID"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@location" headerText="Location"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="job" headerText="Job"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="address" headerText="Address"/>

</mx:columns>

</mx:DataGrid>

</mx:Canvas>



<mx:Canvas label="Inactive" width="100%" height="100%"
id="canvas2" initialize="RefreshData();">

<mx:DataGrid id="inactiveData" dataProvider="{xInActive}"
selectedIndex="0" editable="true" enabled="true">

<mx:columns>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@name" headerText="Name"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@id" headerText="ID"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@location" headerText="Location"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="job" headerText="Job"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="address" headerText="Address"/>

</mx:columns>

</mx:DataGrid>

</mx:Canvas>

</mx:TabNavigator>

</mx:Application>

View solution in original post

2 Replies

Avatar

Level 3
Looking at the examples I found this



<mx:HTTPService id="srv" url="catalog.xml"
result="list.filter(filterItem, true)"/>



<AnimatedTileList id="list"
dataProvider="{srv.lastResult.catalog.product}"

itemRenderer="Thumbnail" width="700" height="528"/>



Notice the lastResult not result.

Avatar

Correct answer by
Level 1
After a little digging and a couple cups of coffee, I managed
to pull some data extracting from xml into a datagrid. I can access
attributes, node values, etc...



One thing I did notice, is that you have to refresh the
application if you have dynamic data constantly being updated. So
here is some code to help some of you out:





First some sample XML (index.xml):





<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<records>

<active name="John" id="1234" location="New York">

<job>Architect</job>

<address>111 Salisbury Rd</address>

</active>



<inactive name="Chris" id="5432" location="California">

<job>Web Designer</job>

<address>888 Orchard Rd</address>

</inactive>



</records>








Code with two tabs one name (
Active), other named (
Inactive):






<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" xmlns:local="*" pageTitle="Test App"
creationComplete="srv.send()">



<mx:HTTPService id="srv" url="
http://www.domain.com/index.xml?rand=math.random();"
resultFormat="e4x" useProxy="false" showBusyCursor="true" />

<mx:XMLListCollection id="xActive"
source="{srv.lastResult.active}" />

<mx:XMLListCollection id="xInActive"
source="{srv.lastResult.inactive}" />



<mx:script>

<[[

private function RefreshData():void{

xActive.refresh();

xInActive.refresh();

}

]]>

</mx:Script>



<mx:TabNavigator>

<mx:Canvas label="Active" width="100%" height="100%"
id="canvas1" initialize="RefreshData();">

<mx:DataGrid id="activeData" dataProvider="{xActive}"
selectedIndex="0" editable="true" enabled="true">

<mx:columns>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@name" headerText="Name"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@id" headerText="ID"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@location" headerText="Location"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="job" headerText="Job"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="address" headerText="Address"/>

</mx:columns>

</mx:DataGrid>

</mx:Canvas>



<mx:Canvas label="Inactive" width="100%" height="100%"
id="canvas2" initialize="RefreshData();">

<mx:DataGrid id="inactiveData" dataProvider="{xInActive}"
selectedIndex="0" editable="true" enabled="true">

<mx:columns>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@name" headerText="Name"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@id" headerText="ID"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="@location" headerText="Location"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="job" headerText="Job"/>

<mx:DataGridColumn textAlign="center" resizable="false"
dataField="address" headerText="Address"/>

</mx:columns>

</mx:DataGrid>

</mx:Canvas>

</mx:TabNavigator>

</mx:Application>