extracting xml cdata with actionscript 3 - actionscript-3
I have been racking my brain trying to extract the cdata from xml with no success. Here is my code.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="myData.send();" backgroundColor="white" >
<mx:HTTPService id="myData" resultFormat="e4x" url="./assets/rawXML.xml" result="handleResult1(event)"/>
<mx:Script><![CDATA[
import mx.collections.XMLListCollection;
import mx.rpc.events.*;
[Bindable]
private var firstName:String;
[Bindable]
private var myXML:XMLList;
private function handleResult1(event:ResultEvent):void{
myXML = event.result.ROW;
for each(var siteXML:XML in myXML){
firstName = siteXML..SC_DF_FIELD_3.text();
}
}
]]>
</mx:Script>
<mx:TextArea text = "{firstName}" height="200" width="800"/>
</mx:Application>
Here is my XML;
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="myFirstTemplate.xsl"?>
<ViewAll>
<RECORDSET_METADATA>
<STARTREC>1</STARTREC>
<KEYFIELDS>True</KEYFIELDS>
<ENDREC>6</ENDREC>
<TOTALREC>6</TOTALREC>
<PAGE_NO>1</PAGE_NO>
<SORT_TYPE>DT_UPDATED</SORT_TYPE>
<SORT_ORDER>desc</SORT_ORDER>
<FORM_ID>414898</FORM_ID>
<REPORT_ID></REPORT_ID>
<SAVED_ID></SAVED_ID>
<NEXTSORTORDER>
<![CDATA[&sortorder=desc]]>
</NEXTSORTORDER>
<SC_DF_XSL_HELP_URL>
<![CDATA[http://libraries.ge.com/LibrariesWiki/2767051101/Data%20Forms%20-%20Customizing%20Records%20View]]>
</SC_DF_XSL_HELP_URL>
<FILTER_DATA>
<![CDATA[var AdvSrchFltrXML_String = { AdvSrchFltrData : { filter : [ {selElementType : '',selElementParentDF : '',selComb : '',exclCheck : '',selElement : '',query : '',query_psrch : '',includeNull : '',lockFilter : '',lockFilterFlg : '',dateFrom : '',dateTo : '',betweenDaysFrom : '',betweenDaysTo : '',betweenDaysFromOption : '',betweenDaysToOption : '',exactDaysOption : '',exactDays : '',moreThanOption : '',moreThan : '',NumAgingQuery : '',betweenNumFrom : '',betweenNumTo : '',GreaterOrLessOrEqualToNum : '',dateFromFormat : '',dateToFormat : ''} ] },size : 1, HiddenXMLFilterCount :''}]]>
</FILTER_DATA>
<FILTER_FIELDS>
<![CDATA[ var arrFields = new Array(new Array("form_doc_id","Entry #","req","","","","",""),new Array("LOGGED_BY","Logged By","psrch","","","","","1"),new Array("DT_LOGGED","Date Logged","dt","","","","",""),new Array("LAST_UPDATED_BY","Last Updated By","psrch","","","","","1"),new Array("DT_UPDATED","Date Updated","dt","","","","",""),new Array("el_values_field3","Name","t","","","5707420","alpha","0"))]]>
</FILTER_FIELDS>
<GENERATE_HIDDEN_VAR>
<![CDATA[]]>
</GENERATE_HIDDEN_VAR>
<HIDDEN_XML_FILTER_COUNT>
<![CDATA[]]>
</HIDDEN_XML_FILTER_COUNT>
<HIDDEN_FILTER_REMOVE_NUMBER>
<![CDATA[]]>
</HIDDEN_FILTER_REMOVE_NUMBER>
<DF_LINK_FIELDS_VAR>
<![CDATA[]]>
</DF_LINK_FIELDS_VAR>
<SA_UPLOAD_FLAG>
<![CDATA[-1]]>
</SA_UPLOAD_FLAG>
<FLG_EXPORT_PDF_WORD>0</FLG_EXPORT_PDF_WORD>
<FLG_DISABLE_BULK_UPDATE_APPEND>0</FLG_DISABLE_BULK_UPDATE_APPEND>
<FLG_EXPORT_KML>1</FLG_EXPORT_KML>
<FLG_EXPORT_TO_MAP>0</FLG_EXPORT_TO_MAP>
<FLGFULLTXTSEARCH>0</FLGFULLTXTSEARCH>
<PUBLISHED_FLAG>0</PUBLISHED_FLAG>
<STR_CREATE_ORDER>402</STR_CREATE_ORDER>
<FUNC_CREATE_ORDER>asc</FUNC_CREATE_ORDER>
<FORM_NAME>FSR Map Points</FORM_NAME>
<PROD_ID>267672</PROD_ID>
<ARCHIVE_FLAG>0</ARCHIVE_FLAG>
<FACILITATOR_FLAG>1</FACILITATOR_FLAG>
<ADVANCED_SEARCH_FLAG>1</ADVANCED_SEARCH_FLAG>
<EXPORT_ALL_FLAG>1</EXPORT_ALL_FLAG>
<EXPORT_PAGE_FLAG>0</EXPORT_PAGE_FLAG>
<DELETE_RECORD_FLAG>1</DELETE_RECORD_FLAG>
<FIELDCHOOSER_EDIT_FLAG>1</FIELDCHOOSER_EDIT_FLAG>
<FIELDCHOOSER_COPY_FLAG>1</FIELDCHOOSER_COPY_FLAG>
<RSS_FEED>1</RSS_FEED>
<FIELD_CHOOSER_ENABLE_FLAG>1</FIELD_CHOOSER_ENABLE_FLAG>
<ARCHIVE_ALL_ENABLE_FLAG>1</ARCHIVE_ALL_ENABLE_FLAG>
<TRUNCATE_TEXT_FLAG>0</TRUNCATE_TEXT_FLAG>
<CALLED_FOR></CALLED_FOR>
<CALLING_ENTITY_TYPE></CALLING_ENTITY_TYPE>
<EXCELUPLOADFLAG>true</EXCELUPLOADFLAG>
<VIEWAUDITTRAIL>1</VIEWAUDITTRAIL>
<STATICSERVER>//static.supportcentral.com</STATICSERVER>
<VIEWERS_DETAIL>
<V_SSO_ID>222222222</V_SSO_ID>
<V_PERSON_ID>1273000</V_PERSON_ID>
<V_FIRST_NAME>Geoffrey</V_FIRST_NAME>
<V_LAST_NAME>Goodman</V_LAST_NAME>
<V_BUSINESS_SEGMENT>Power & Water</V_BUSINESS_SEGMENT>
<V_FOCUS_GROUP>GE Power & Water</V_FOCUS_GROUP>
<V_SUB_BUSINESS>PW-WTR Water</V_SUB_BUSINESS>
<V_LANGUAGE>english</V_LANGUAGE>
<V_FUNCTION>Services</V_FUNCTION>
</VIEWERS_DETAIL>
</RECORDSET_METADATA>
<DFLINK_ELEMENT_DETAILS>
<CalledForSF display_name="CalledForSF" search_field="No"> </CalledForSF>
<SOURCE_ELEMENT_ID display_name="SOURCE_ELEMENT_ID" search_field="No"> </SOURCE_ELEMENT_ID>
<TARGET_ELEMENT_ID display_name="TARGET_ELEMENT_ID" search_field="No"> </TARGET_ELEMENT_ID>
</DFLINK_ELEMENT_DETAILS>
<DF_FIELDS>
<SC_SYS_DF_FORM_DOC_ID display_name="Entry #" search_field="Yes">Entry #</SC_SYS_DF_FORM_DOC_ID>
<SC_SYS_DF_DT_LOGGED display_name="Date Logged" search_field="Yes">Logged Date</SC_SYS_DF_DT_LOGGED>
<SC_SYS_DF_DT_UPDATED display_name="Date Updated" search_field="Yes">Last Updated Date</SC_SYS_DF_DT_UPDATED>
<SC_SYS_DF_LOGGED_BY display_name="Logged By" search_field="Yes">Logged by</SC_SYS_DF_LOGGED_BY>
<SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By" search_field="Yes">Last Updated By</SC_SYS_DF_LAST_UPDATED_BY>
<SC_SYS_DF_AUDIT_TRAIL_HEADER display_name="Audit Trail" search_field="Yes">Audit Trail</SC_SYS_DF_AUDIT_TRAIL_HEADER>
<SC_DF_FIELD_3 display_name="Name" element_type="t" search_field="Yes" Inactive_user="0">Name</SC_DF_FIELD_3>
</DF_FIELDS>
<HEADER>
<SC_SYS_DF_FORM_DOC_ID display_name="Entry #" search_field="Yes">Entry #</SC_SYS_DF_FORM_DOC_ID>
<SC_SYS_DF_DT_LOGGED display_name="Date Logged" search_field="Yes">Logged Date</SC_SYS_DF_DT_LOGGED>
<SC_SYS_DF_DT_UPDATED display_name="Date Updated" search_field="Yes">Last Updated Date</SC_SYS_DF_DT_UPDATED>
<SC_SYS_DF_LOGGED_BY display_name="Logged By" search_field="Yes">Logged by</SC_SYS_DF_LOGGED_BY>
<SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By" search_field="Yes">Last Updated By</SC_SYS_DF_LAST_UPDATED_BY>
<SC_SYS_DF_AUDIT_TRAIL display_name="Audit Trail" search_field="Yes">Audit Trail</SC_SYS_DF_AUDIT_TRAIL>
<SC_DF_FIELD_1 display_name="Menu L1" element_type="t" search_field="No">Menu L1</SC_DF_FIELD_1>
<SC_DF_FIELD_2 display_name="Menu L2" element_type="t" search_field="No">Menu L2</SC_DF_FIELD_2>
<SC_DF_FIELD_3 display_name="Name" element_type="t" search_field="Yes">Name</SC_DF_FIELD_3>
<SC_DF_FIELD_4 display_name="Information" element_type="t" search_field="No">Information</SC_DF_FIELD_4>
<SC_DF_FIELD_5 display_name="City, State" element_type="t" search_field="No">City, State</SC_DF_FIELD_5>
<SC_DF_FIELD_6 display_name="Latitude" element_type="t" search_field="No">Latitude</SC_DF_FIELD_6>
<SC_DF_FIELD_7 display_name="Longitude" element_type="t" search_field="No">Longitude</SC_DF_FIELD_7>
</HEADER>
<ROW edit_access="1">
<SC_SYS_DF_FORM_DOC_ID_ACTION display_name="Entry # For Actions">
<![CDATA[6193418162]]>
</SC_SYS_DF_FORM_DOC_ID_ACTION>
<SC_SYS_DF_FORM_DOC_ID display_name="Entry #">
<![CDATA[6193418162]]>
<ENTRY_VIEW_URL display_name="View Entry URL">
<![CDATA[http://supportcentral.com/dataforms/sup_dataform_display.asp?dataform_id=414898&dataform_doc_id=6193418162]]>
</ENTRY_VIEW_URL>
</SC_SYS_DF_FORM_DOC_ID>
<SC_SYS_DF_DT_LOGGED display_name="Date Logged">
<![CDATA[4/4/2013 9:27:46 AM]]>
</SC_SYS_DF_DT_LOGGED>
<SC_SYS_DF_DT_UPDATED display_name="Date Updated">
<![CDATA[4/4/2013 9:27:46 AM]]>
</SC_SYS_DF_DT_UPDATED>
<SC_SYS_DF_LOGGED_BY display_name="Logged By">
<![CDATA[ ]]>
<PERSON>
<SC_DF_PERSON_LINK display_name="Profile Url">
<![CDATA[../common/sup_persondtls.asp?p_id=2348753]]>
</SC_DF_PERSON_LINK>
<SC_DF_SSO display_name="">
<![CDATA[218010000]]>
</SC_DF_SSO>
<SC_DF_EMAIL display_name="Email">
<![CDATA[joseph.ulo#go.com]]>
</SC_DF_EMAIL>
<SC_DF_FIRST_NAME display_name="First Name">
<![CDATA[Joseph]]>
</SC_DF_FIRST_NAME>
<SC_DF_LAST_NAME display_name="Last Name">
<![CDATA[ulo]]>
</SC_DF_LAST_NAME>
</PERSON>
<PERSON_STRING>
<PERSON_STRING_VAR display_name="person person person">
<![CDATA[var person_String = {person : [ {PERSON_ID : '../common/sup_persondtls.asp?p_id=2348753',FIRST_NAME : 'Joseph',LAST_NAME:'ulo'}], size : 1 }]]>
</PERSON_STRING_VAR>
</PERSON_STRING>
</SC_SYS_DF_LOGGED_BY>
<SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By">
<![CDATA[ ]]>
<PERSON>
<SC_DF_PERSON_LINK display_name="Profile Url">
<![CDATA[../common/sup_persondtls.asp?p_id=2348753]]>
</SC_DF_PERSON_LINK>
<SC_DF_SSO display_name="">
<![CDATA[218010000]]>
</SC_DF_SSO>
<SC_DF_EMAIL display_name="Email">
<![CDATA[joseph.ulo#go.com]]>
</SC_DF_EMAIL>
<SC_DF_FIRST_NAME display_name="First Name">
<![CDATA[Joseph]]>
</SC_DF_FIRST_NAME>
<SC_DF_LAST_NAME display_name="Last Name">
<![CDATA[ulo]]>
</SC_DF_LAST_NAME>
</PERSON>
<PERSON_STRING>
<PERSON_STRING_VAR display_name="person person person">
<![CDATA[var person_String = {person : [ {PERSON_ID : '../common/sup_persondtls.asp?p_id=2348753',FIRST_NAME : 'Joseph',LAST_NAME:'ulo'}], size : 1 }]]>
</PERSON_STRING_VAR>
</PERSON_STRING>
</SC_SYS_DF_LAST_UPDATED_BY>
<SC_SYS_DF_AUDIT_TRAIL display_name="Audit Trail">
<![CDATA[Audit Trail]]>
</SC_SYS_DF_AUDIT_TRAIL>
<SC_DF_FIELD_1 display_name="Menu L1" element_type="t" data_type="alpha">
<![CDATA[FSR]]>
</SC_DF_FIELD_1>
<SC_DF_FIELD_2 display_name="Menu L2" element_type="t" data_type="alpha">
<![CDATA[Mobile Man]]>
</SC_DF_FIELD_2>
<SC_DF_FIELD_3 display_name="Name" element_type="t" data_type="alpha">
<![CDATA[ulo, Joseph]]>
</SC_DF_FIELD_3>
<SC_DF_FIELD_4 display_name="Information" element_type="t" data_type="alpha">
<![CDATA[Northeast Territory]]>
</SC_DF_FIELD_4>
<SC_DF_FIELD_5 display_name="City, State" element_type="t" data_type="alpha">
<![CDATA[Virginia Beach, VA]]>
</SC_DF_FIELD_5>
<SC_DF_FIELD_6 display_name="Latitude" element_type="t" data_type="alpha">
<![CDATA[-75.977976563656]]>
</SC_DF_FIELD_6>
<SC_DF_FIELD_7 display_name="Longitude" element_type="t" data_type="alpha">
<![CDATA[36.852930519206]]>
</SC_DF_FIELD_7>
</ROW>
<ROW edit_access="1">
<SC_SYS_DF_FORM_DOC_ID_ACTION display_name="Entry # For Actions">
<![CDATA[6193418164]]>
</SC_SYS_DF_FORM_DOC_ID_ACTION>
<SC_SYS_DF_FORM_DOC_ID display_name="Entry #">
<![CDATA[6193418164]]>
<ENTRY_VIEW_URL display_name="View Entry URL">
<![CDATA[http://supportcentral.com/dataforms/sup_dataform_display.asp?dataform_id=414898&dataform_doc_id=6193418164]]>
</ENTRY_VIEW_URL>
</SC_SYS_DF_FORM_DOC_ID>
<SC_SYS_DF_DT_LOGGED display_name="Date Logged">
<![CDATA[4/4/2013 9:27:46 AM]]>
</SC_SYS_DF_DT_LOGGED>
<SC_SYS_DF_DT_UPDATED display_name="Date Updated">
<![CDATA[4/4/2013 9:27:46 AM]]>
</SC_SYS_DF_DT_UPDATED>
<SC_SYS_DF_LOGGED_BY display_name="Logged By">
<![CDATA[ ]]>
<PERSON>
<SC_DF_PERSON_LINK display_name="Profile Url">
<![CDATA[../common/sup_persondtls.asp?p_id=3282603]]>
</SC_DF_PERSON_LINK>
<SC_DF_SSO display_name="">
<![CDATA[2180200000]]>
</SC_DF_SSO>
<SC_DF_EMAIL display_name="Email">
<![CDATA[kevin.woodsman#go.com]]>
</SC_DF_EMAIL>
<SC_DF_FIRST_NAME display_name="First Name">
<![CDATA[Kevin]]>
</SC_DF_FIRST_NAME>
<SC_DF_LAST_NAME display_name="Last Name">
<![CDATA[Woodsman]]>
</SC_DF_LAST_NAME>
</PERSON>
<PERSON_STRING>
<PERSON_STRING_VAR display_name="person person person">
<![CDATA[var person_String = {person : [ {PERSON_ID : '../common/sup_persondtls.asp?p_id=3282603',FIRST_NAME : 'Kevin',LAST_NAME:'Woodsman'}], size : 1 }]]>
</PERSON_STRING_VAR>
</PERSON_STRING>
</SC_SYS_DF_LOGGED_BY>
<SC_SYS_DF_LAST_UPDATED_BY display_name="Last Updated By">
<![CDATA[ ]]>
<PERSON>
<SC_DF_PERSON_LINK display_name="Profile Url">
<![CDATA[../common/sup_persondtls.asp?p_id=3282603]]>
</SC_DF_PERSON_LINK>
<SC_DF_SSO display_name="">
<![CDATA[218020000]]>
</SC_DF_SSO>
<SC_DF_EMAIL display_name="Email">
<![CDATA[kevin.woodsman#go.com]]>
</SC_DF_EMAIL>
<SC_DF_FIRST_NAME display_name="First Name">
<![CDATA[Kevin]]>
</SC_DF_FIRST_NAME>
<SC_DF_LAST_NAME display_name="Last Name">
<![CDATA[Woodsman]]>
</SC_DF_LAST_NAME>
</PERSON>
<PERSON_STRING>
<PERSON_STRING_VAR display_name="person person person">
<![CDATA[var person_String = {person : [ {PERSON_ID : '../common/sup_persondtls.asp?p_id=3282603',FIRST_NAME : 'Kevin',LAST_NAME:'Woodsman'}], size : 1 }]]>
</PERSON_STRING_VAR>
</PERSON_STRING>
</SC_SYS_DF_LAST_UPDATED_BY>
<SC_SYS_DF_AUDIT_TRAIL display_name="Audit Trail">
<![CDATA[Audit Trail]]>
</SC_SYS_DF_AUDIT_TRAIL>
<SC_DF_FIELD_1 display_name="Menu L1" element_type="t" data_type="alpha">
<![CDATA[FSR]]>
</SC_DF_FIELD_1>
<SC_DF_FIELD_2 display_name="Menu L2" element_type="t" data_type="alpha">
<![CDATA[Mobile Man]]>
</SC_DF_FIELD_2>
<SC_DF_FIELD_3 display_name="Name" element_type="t" data_type="alpha">
<![CDATA[Woodsman, Kevin]]>
</SC_DF_FIELD_3>
<SC_DF_FIELD_4 display_name="Information" element_type="t" data_type="alpha">
<![CDATA[Northeast Territory]]>
</SC_DF_FIELD_4>
<SC_DF_FIELD_5 display_name="City, State" element_type="t" data_type="alpha">
<![CDATA[Manchester, NH]]>
</SC_DF_FIELD_5>
<SC_DF_FIELD_6 display_name="Latitude" element_type="t" data_type="alpha">
<![CDATA[-71.454786492200]]>
</SC_DF_FIELD_6>
<SC_DF_FIELD_7 display_name="Longitude" element_type="t" data_type="alpha">
<![CDATA[42.995647573539]]>
</SC_DF_FIELD_7>
</ROW>
</ViewAll>
Any suggestions on how to get the SC_DF_FIELD_3 field to increment? No matter what I try I only get the last name (Woodsman, Kevin) to appear. Im pretty sure its overwriting the fistname variable in the for each loop but im not sure how to change it. Any help would be greatly appraciated!
Assuming that you want shows the ALL the names in the TextArea component, and asumming that your code works.
If you want to show this:
ulo
Joseph
Woodsman
Kevin
Maybe this will be useful:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="myData.send();" backgroundColor="white" >
<mx:HTTPService id="myData" resultFormat="e4x" url="./assets/rawXML.xml" result="handleResult1(event)"/>
<mx:Script><![CDATA[
import mx.collections.XMLListCollection;
import mx.rpc.events.*;
private var names:String;
[Bindable]
private var myXML:XMLList;
private function handleResult1(event:ResultEvent):void{
myXML = event.result.ROW;
names= "";
for each(var siteXML:XML in myXML){
names= names + '-' + siteXML..SC_DF_FIELD_3.text();
}
txtArea.text = names;
}
]]>
</mx:Script>
<mx:TextArea id="txtArea" height="200" width="800" />
</mx:Application>
Try it and tell me f it worked.
Related
Send a flag instead a letter based in a json
i don't know if i expleined i receive a json from an odata call and i send it to my table but one field have a X or is empty but instead of showing a X i want to show a flag like in ObjectListItem with a ObjectMarker type="Flagged" and just showing the flag my table: (i delete some colums for this but my field that i'm interested is Sucursalescolacion and Sucursalesflag) <Table id="bSucursales" inset="false" items="{/}" visible="false" enableBusyIndicator="true"> <columns> <Column> <Text text="{i18n>colSucursalesid}" /> </Column> <Column> <Text text="{i18n>colSucursalesnombre}" /> </Column> <Column> <Text text="{i18n>colSucursalesdircalle}" /> </Column> <Column> <Text text="{i18n>colSucursalesdirnumero}" /> </Column> </columns> <items> <ColumnListItem press="" type="Active"> <Text text="{Sucursalesdepto}"/> <Text text="{Sucursalesfono1}"/> <Text text="{Sucursalesfono2}"/> <Text text="{Sucursalesactiva}"/> <Text text="{Sucursaleshoraini}"/> <Text text="{Sucursaleshorafin}"/> <Text text="{Sucursalescolacion}"/> <!-- <ObjectMarker type="Flagged"/> --> <Text text="{Sucursalesflag}"/> </ColumnListItem> </items> </Table> my controller var bSucursales = this.byId("bSucursales"); bSucursales.setVisible(true); oDataModel.read("/" + resultado2 +"?$filter=Maestropais eq '" + resultado + "'" + "and Maestrometodo eq '" + metodo + "'", { success: function(oData, response) { var oResults = oData.results; oModel.setData(oResults); bSucursales.setModel(oModel); }, error: function(oError) { } });
You could use expression binding: <ObjectMarker type="{= ${Sucursalesflag} === 'X' : 'Flagged' : ''}" /> More info: https://sapui5.hana.ondemand.com/#/topic/5cff8d1c3fb84c5db7a00f2daca125af
Also, you can choose to use a formatter as: <ObjectMarker type="{path: 'Sucursalesflag', formatter: '.formatSalesFlag'}"/> Define formatter function in your controller: . . . statusText: function (sSalesFlag) { if(sSalesFlag == 'X'){ return 'Flagged'; } else{ return ''; } } } You can write more complex custom formatters for different use-cases. Learn more about customer formatters here
Converting this XMLList to XML
var xml:XML = new XML( <root> <message for="Harry" > adlfjljfa </message> <message for="Harry" > ajf ja; jafja </message> <message for="Akil"> difasfjlfjals </message> var xmlList:XMLList = xml.message.(#for== "Harry" ) var nameXML:XML = XML(xmlList) trace( nameXML ) Right now the nameXML doesnot form correctly, and throws an error : The markup in the document following the root element must be well formed. Thanks
You didnt close the root tag in the XML declaration. I replaced the "for" attribute because its reserved. var xml:XML = <root> <message dest="Harry" > adlfjljfa </message> <message dest="Harry" > ajf ja; jafja </message> <message dest="Akil"> difasfjlfjals </message> </root> var xmlList:XMLList = xml.message.(#dest== "Harry" ) for each (var item:XML in xmlList) { trace(item) } output adlfjljfa ajf ja; jafja Edit You can also keep the "for" attribute : var xmlList:XMLList = xml.message.(attribute('for')== "Harry" )
Display placemark name in openstreetmap from an external KML file using Openlayers
I am trying to load a KML file of a particular state and display the counties with its name .I am using the following code . map = new OpenLayers.Map({ div: "map_canvas", allOverlays: true }); var osm = new OpenLayers.Layer.OSM(); var styleMap = new OpenLayers.StyleMap({'default':{ label : "${name}" }}); var sundials = new OpenLayers.Layer.Vector("KML", { projection: map.displayProjection, strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({ url: "Minnesota.kml", format: new OpenLayers.Format.KML({ // extractStyles: true, extractAttributes: true // kvpAttributes: false }), styleMap: styleMap }) }); map.addLayers([osm,sundials]); map.addControl(new OpenLayers.Control.LayerSwitcher()); map.setCenter(new OpenLayers.LonLat(0, 0), 3); Now the KML file is shown properly but the county names are not shown.(resulting image is attached)! The XML file looks like <Document> <name>United States Counties</name> <Style id='Style3-polygon-1'> <LabelStyle> <scale>0.8</scale> </LabelStyle> <LineStyle> <color>ffa8d7b6</color> <width>1</width> </LineStyle> <PolyStyle> <color>ff29c773</color> </PolyStyle> <BalloonStyle> <text>$[description]</text> </BalloonStyle> </Style> <Style id='Style3-polygon-1-hover'> <LineStyle> <color>ffa8d7b6</color> <width>1</width> </LineStyle> <PolyStyle> <color>ff29c773</color> </PolyStyle> <BalloonStyle> <text>$[description]</text> </BalloonStyle> </Style> <StyleMap id='Style3-polygon-1-map'> <Pair> <key>normal</key> <styleUrl>#Style3-polygon-1</styleUrl> </Pair> <Pair> <key>highlight</key> <styleUrl>#Style3-polygon-1-hover</styleUrl> </Pair> </StyleMap> <Placemark> <name>Aitkin</name> <snippet></snippet> <description><![CDATA[<div> MN-Aitkin </div>]]></description> <styleUrl>#Style3-polygon-1-map</styleUrl> <ExtendedData> <Data name='State Abbr.'> <value>MN-Aitkin</value> </Data> <Data name='County Name'> <value>mn</value> </Data> <Data name='State-County'> <value>MN</value> </Data> <Data name='value'> <value>526.0226226</value> </Data> <Data name='GEO_ID'> <value>05000US27001</value> </Data> <Data name='GEO_ID2'> <value>27001</value> </Data> <Data name='Geographic Name'> <value>Aitkin County, Minnesota</value> </Data> <Data name='STATE num'> <value>27</value> </Data> <Data name='COUNTY num'> <value>1</value> </Data> <Data name='FIPS formula'> <value>27001.0</value> </Data> <Data name='Has error'> <value></value> </Data> </ExtendedData><Polygon><outerBoundaryIs><LinearRing><coordinates>-93.05408,46.20649 -93.05421,46.20823 -93.05419,46.20965 -93.05412,46.21283 -93.05409,46.2138 -93.05403,46.21847 -93.054,46.2261 -93.05412,46.24161 -93.05419,46.24676 -93.0541,46.26842 -93.05407,46.28187 -93.0538,46.31176 -93.05374,46.32576 -93.05378,46.32944 -93.05371,46.33036 -93.05376,46.33888 -93.05407,46.36721 -93.05412,46.3804 -93.05418,46.38731 -93.05473,46.4148 -93.05485,46.41927 -93.05489,46.42117 -93.05533,46.43976 -93.05533,46.44373 -93.05531,46.45141 -93.05525,46.46333 -93.05529,46.47313 -93.05536,46.52685 -93.05541,46.53137 -93.05551,46.5389 -93.05575,46.56708 -93.05481,46.59258 -93.06371,46.62103 -93.06388,46.62991 -93.06377,46.63054 -93.06385,46.63295 -93.06447,46.6547 -93.0648,46.67386 -93.0647,46.68015 -93.06454,46.68285 -93.06459,46.68415 -93.06442,46.68815 -93.06414,46.6919 -93.0638,46.69672 -93.0635,46.70887 -93.06286,46.7377 -93.06179,46.76189 -93.06153,46.76655 -93.06153,46.7666 -93.06113,46.78424 -93.06103,46.78869 -93.06101,46.78939 -93.06083,46.79786 -93.05986,46.8421 -93.05947,46.85365 -93.05932,46.85812 -93.05894,46.86951 -93.05884,46.87494 -93.05894,46.88162 -93.05893,46.88191 -93.05889,46.88584 -93.05875,46.8944 -93.05861,46.89914 -93.05827,46.9106 -93.05826,46.91086 -93.05798,46.92368 -93.0579,46.93014 -93.05777,46.93965 -93.05756,46.94973 -93.057,46.98125 -93.05672,46.99994 -93.05658,47.00732 -93.05629,47.0161 -93.05601,47.0244 -93.05594,47.02641 -93.056,47.02641 -93.07411,47.02637 -93.09664,47.02632 -93.17387,47.02546 -93.18728,47.02525 -93.23808,47.02615 -93.25289,47.02641 -93.27663,47.02684 -93.28055,47.02691 -93.28582,47.02701 -93.29009,47.02719 -93.29575,47.02742 -93.30887,47.02797 -93.32855,47.02827 -93.43947,47.02838 -93.56249,47.02944 -93.57709,47.02941 -93.58646,47.02954 -93.59338,47.02966 -93.59822,47.02955 -93.60745,47.0295 -93.62885,47.02934 -93.6533,47.02898 -93.66564,47.02902 -93.67942,47.02914 -93.76285,47.03025 -93.77526,47.03042 -93.77528,47.02869 -93.77492,47.00431 -93.77477,46.98089 -93.77487,46.97538 -93.77503,46.96505 -93.77511,46.95953 -93.77521,46.95727 -93.77521,46.95458 -93.77522,46.95212 -93.77521,46.94862 -93.77525,46.9432 -93.77517,46.93924 -93.77508,46.93543 -93.77502,46.93207 -93.77497,46.92857 -93.77489,46.91516 -93.77508,46.88938 -93.77516,46.88185 -93.77525,46.87495 -93.77531,46.86655 -93.77536,46.86175 -93.77552,46.85637 -93.77555,46.85117 -93.77555,46.84822 -93.77586,46.81778 -93.77601,46.80405 -93.77602,46.80289 -93.77685,46.77329 -93.77714,46.73442 -93.77803,46.67766 -93.77829,46.63291 -93.77821,46.6137 -93.77791,46.59013 -93.79094,46.58774 -93.8028,46.58513 -93.81137,46.56775 -93.81092,46.55284 -93.81076,46.53363 -93.8114,46.51584 -93.81217,46.50219 -93.81169,46.48339 -93.81117,46.45739 -93.81078,46.44177 -93.81015,46.41986 -93.81018,46.41236 -93.81019,46.40837 -93.8103,46.4021 -93.81061,46.34182 -93.81067,46.31164 -93.81042,46.25105 -93.80718,46.24811 -93.80691,46.24797 -93.79946,46.24878 -93.79628,46.2432 -93.79615,46.2432 -93.75984,46.24373 -93.72728,46.24409 -93.70808,46.24442 -93.70126,46.24453 -93.69065,46.24468 -93.68406,46.24478 -93.66084,46.24512 -93.63685,46.24555 -93.62916,46.2456 -93.54353,46.24701 -93.5268,46.24713 -93.505,46.24693 -93.49318,46.24678 -93.43065,46.24641 -93.43047,46.23706 -93.43042,46.23021 -93.43044,46.22114 -93.43011,46.20857 -93.42982,46.19637 -93.4296,46.1832 -93.42989,46.17337 -93.43016,46.16611 -93.43034,46.16178 -93.43129,46.15656 -93.43182,46.15418 -93.43183,46.15399 -93.42058,46.15427 -93.40637,46.15462 -93.38262,46.1557 -93.3268,46.15804 -93.30847,46.15886 -93.30489,46.15891 -93.28945,46.1593 -93.27752,46.15939 -93.2729,46.15937 -93.26847,46.15939 -93.26439,46.15946 -93.25833,46.15921 -93.23084,46.15876 -93.17898,46.15855 -93.15425,46.15833 -93.13983,46.15824 -93.13535,46.15822 -93.12296,46.15829 -93.11547,46.1584 -93.10791,46.15838 -93.10298,46.15835 -93.09377,46.15833 -93.08377,46.15831 -93.07403,46.15829 -93.06795,46.1583 -93.05528,46.15827 -93.05387,46.15812 -93.05387,46.15821 -93.05388,46.16661 -93.05404,46.18284 -93.05417,46.18951 -93.05419,46.19383 -93.05421,46.19823</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark> <Style id='Style3-polygon-2'> How do I display the names of the counties on the map ?
I think you need a context too: var styleMap = new OpenLayers.StyleMap({ "default": new OpenLayers.Style({ label: "${label}" }, { context: { label: function (feature) { return feature.attributes.name; } } }) });
Get prefix of XML namespace from URI
How can I get the prefix of a xml namespace from URI? example: <Name xmlns:tiger="http://www.census.gov"> </Name> I've got the "http://www.census.gov" I want to get the prefix tiger How can I do this in Actionscript / Flex? thx EDIT The answer doesn't work with this complex example: <Name xmlns:tiger="http://www.census.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:worldWS="worldWS" xmlns:sde="http://geoserver.sf.net" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:nurc="http://www.nurc.nato.int" xmlns:solWS="solWS"> tiger:poly_landmarks </Name> I've got empty Array. ANSWER MY OWN Q for EDIT example var xml:XML = <Name xmlns:tiger="http://www.census.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:worldWS="worldWS" xmlns:sde="http://geoserver.sf.net" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:nurc="http://www.nurc.nato.int" xmlns:solWS="solWS"> tiger:poly_landmarks </Name> var ns:Namespace = xml.namespace("http://www.census.gov"); if(ns.uri == "http://www.census.gov") ....
var xml:XML = <Name xmlns:tiger="http://www.census.gov"></Name>; var ns:Array = xml.namespaceDeclarations(); trace(ns[0].prefix); //output: tiger UPD for complex xml (output tiger as well): var xml:XML = <Name xmlns:tiger="http://www.census.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:worldWS="worldWS" xmlns:sde="http://geoserver.sf.net" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:nurc="http://www.nurc.nato.int" xmlns:solWS="solWS"> tiger:poly_landmarks </Name> var nss:Array = xml.namespaceDeclarations(); for each(var ns:Namespace in nss) { if(ns.uri == "http://www.census.gov") { trace(ns.prefix); break; } }
CDATA not supporting to read data from XMLList
XML : <catering> <contents> <![CDATA[ <title>UPCOMING EVENTS</title> <info _title = "<font size='14' color='#ffffff'>title1</font" image="null"></info> <info _title = "title2" image="images/events/slide1.jpg"></info> <info _title = "title3 " image="images/events/slide2.jpg"></info> <info _title = "title4" image="images/events/slide3.jpg"></info> <info _title = "title5" image="images/events/slide4.jpg"></info> ]] </contents> </catering> CODE eventTitle = loadXMLC.events_1_Contents.contents.title; xmlList_1 = loadXMLC.events_1_Contents.contents.info; for(i = 0;i < xmlList_1.#_title.length(); i++) { events_0_info.push(xmlList_1.#_title[i]); img_ary0.push(xmlList_1.#image[i]); } Without CDATA I can able to read the XML. What do I needs to do read the data with CDATA? I want to use html tag for each attributes.
Here is a quick exemple : var data : XML = <catering> <contents> <![CDATA[ <title>UPCOMING EVENTS</title> <info _title = "title2" image="images/events/slide1.jpg"></info> <info _title = "title3 " image="images/events/slide2.jpg"></info> <info _title = "title4" image="images/events/slide3.jpg"></info> <info _title = "title5" image="images/events/slide4.jpg"></info> ]]> </contents> </catering>; The nodes between CDATA tag are seen as text (a block of text). You have to convert this text into a valid XML in order to access data. trace(XML(data.contents.children()).nodeKind());//text var contents : XMLList = XML("<c>"+data.contents.toString()+"</c>").children(); trace(contents.toXMLString()); I removed this line from your sample : <info _title = "<font size='14' color='#ffffff'>title1</font" image="null"></info> Flash was unable to convert this line into XML...
I think it's because of a typo where you're closing the CDATA tag. Try adding > at the end like so: <catering> <contents> <![CDATA[ <title>UPCOMING EVENTS</title> <info _title = "<font size='14' color='#ffffff'>title1</font" image="null"></info> <info _title = "title2" image="images/events/slide1.jpg"></info> <info _title = "title3 " image="images/events/slide2.jpg"></info> <info _title = "title4" image="images/events/slide3.jpg"></info> <info _title = "title5" image="images/events/slide4.jpg"></info> ]]> </contents> </catering> and you'll be good to go. EDIT As #OXMO456 mentions. Flash parsing won't go past the first _title attribute. I think the way you're using the xml attributes is a bad practice. In essence attributes contain information about the element, not the content of the element itself. Maybe you should try adjusting the xml structure a bit and try parsing that. Maybe something like this could work: <title>UPCOMING EVENTS</title> <info> <title size="14" color="#ffffff">title1</title> </info> <info> <title>title2</title> <image>images/events/slide2.jpg</image> </info> <info> <title>title3</title> <image>images/events/slide3.jpg</image> </info> <info> <title>title4</title> <image>images/events/slide4.jpg</image> </info>