What is the easiest way to parse XML in ActionScript3/Flex? - apache-flex

What is the easiest way to parse XML in ActionScript3/Flex ?

By using e4X syntax.
Here are a few links to documentation that may help you:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html?filter_flex=4.1&filter_flashplayer=10.1&filter_air=2
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html?filter_flex=4.1&filter_flashplayer=10.1&filter_air=2#top
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e71.html
http://www.ecma-international.org/publications/standards/Ecma-357.htm

We have an XML parser and tutorial here:
http://forea.ch/blog/2010/05/17/utils-parsing-xml/
We also have an XML creator, so you just create the data objects that your application needs and don't have to worry about XML if, for example, you're using XML for configuration data.

If you want to parse a XML to a Object .
you can use FLEXXB .its a wonderful lib.

Related

Using U-SQL MultiLevelJsonExtractor gives Error: Path returned multiple tokens

I am using the MultiLevelJsonExtractor forked on Git by kotvisbj, When I put a Path that contains an array (body.header.items[*] or body.header.items) into the JsonPaths parameter string, I get a "Error: Path returned multiple tokens". Is there a way to extract the paths in code so I can get an array like when using the Root? I tried to explain this the best way I could, I don't have excellent c# skills, it's been a few years.
I think it would be best to ask the owner of the branch to see if he can advise you. I assume that his code expects a single token only and not an array of tokens.
You can probably achieve what you need by using code similar to this: U-SQL - Extract data from json-array

highcharts prepare options for POST

I need to send a Highcharts options object to an asp page so it can be written to a json flat file. These files are later passed to phantomjs via highcharts-convert in order to create some pdfs.
The problem however is stringifying the objects. I keep getting this error:
Uncaught TypeError: Converting circular structure to JSON
when I try this:
$.post("myASP.asp", JSON.stringify(myChart.highcharts().options));
There is a sample POST string here http://docs.highcharts.com/#render-charts-on-the-server but I'm not sure how to achieve that with mine. When I paste their sample into my code for testing I get all kinds of unescaped double quote errors. Is that a typo on their part?
I would check if there are curricular references in the JSON objects. As far as I remember that is not supported by the JSON serializer.
One example of this if you have an object with an array of children that refer back to the parent.
I think you can try the following:
{"infile":myChart.getSVG()}
This should get the svg representation of the chart

XDMP Function: String to XML

Is there any method defined in marklogic function library, by which we can convert (or try to convert) a string (xs:string type) to an xml 'document' type? In my problem, I shall normally get an xml sent through request parameters. now I have to parse this xml as a document. So I have to take it as a string and parse it. What is the solution for this case?
I think xdmp:unquote is what you are looking for.
In XQuery 3.0 simply use the standard XPath 3.0 function parse-xml().
xdmp:eval("<ok/>")
or
xdmp:value("<ok/>")
Both of them can be use for your problem.
Regards

How to validate XQuery source file for XSD schema

I mean without input XML file.
I'm using Saxon-EE 9.2.
if you mean to validate the Xquery source file then, the only route I know of is to first convert it to XqueryX using xq2xqx.xsl and then use a xsd schema based on that
An XQuery source file isn't an XML document, so can't be validated with an XML schema. If you really need to, you can use the xq2xqx library to convert XQuery source files into XQueryX documents:
http://monet.nag.co.uk/xq2xml/
The code there needs some tidying up, the XQuery parser linked at
http://www.w3.org/2005/qt-applets/xgrammar.zip
and the Saxon jar - the free one here should work:
http://saxon.sourceforge.net/#F9.4HE
You should end up with a command line something like:
java -cp "saxon9.jar;xquery.jar;trans2.jar" net.sf.saxon.Transform -it:main -o:"xq2xqx.log" -xsl:"xq2xqx.xsl" dump="no$2" xq=test.xquery
which will generate test.xqueryx, and you can then validate the document against the official w3.org schema:
http://www.w3.org/2005/XQueryX/xqueryx.xsd

Best method to populate XML from SQL query in ASP.NET?

I need to create a service that will return XML containing data from the database. So I am thinking about using an ASHX that will accept things like date range and POST an XML file back. I have dealt with pages pulling data from SQL Server and populating into a datagrid for visual display but never into XML for delivery, what is the best way to do this? Also if an ASHX and POST isn't the best method for delivery let me know... thanks!
EDIT: These answers are great and pointing me in the right direction. I should have also mentioned that the XML format has already been decided so I can't use any automatically generated one.
Combining linq2sqlwith the XElement classes, something along the lines:
var xmlContacts =
new XElement("contacts",
(from c in context.Contacts
select new XElement("contact",
new XElement
{
new XElement("name", c.Name),
new XElement("phone", c.Phone),
new XElement("postal", c.Postal)
)
)
).ToArray()
)
);
Linq2sql will retrieve the data in a single call to the db, and the processing of the XML will be done at the business server. This splits the load better, since you don't have the sql server doing all the job.
Have you tried DataSet.WriteXml()?
You could have this be the output of a web service call.
Sql Server 2005 and above has a "FOR XML AUTO" command that will convert your recordset to XML for you. Then you just have to return a string from your ASHX.
Beginning with SQL Server 2000, you can return query results as XML. For absolute control of them, use the "FOR XML EXPLICIT" command. You can use any format you desire that way.
http://msdn.microsoft.com/en-us/library/ms189068.aspx
It's as easy as writing your result to the raw output then. For added points, you can return the result set to a XPathDocument, pass it through an XSL transformation, and send the results out in any format you choose (HTML vs XML at the click of a button perhaps).
you can obtained that to a datatable and then call myTable.WriteXML()
if you are populating classes with the your database results then add the serializable attribute to the header your classes, and use the XMLSerializer
Converting an automatically generated format into a specified one is a job for xslt. Just find a way to run the output from the tool through an xslt filter.
Oracle has a great product for doing exactly this job - the oracle XDK. But it's a java thing, not ASP as far as I know.
For an example, this XHTML
http://www.anbg.gov.au/abrs/online-resources/flora/stddisplay.xsql?pnid=2524
is generated automatically from this XML, which is generated by oracle
http://www.anbg.gov.au/abrs/online-resources/flora/stddisplay.xsql?pnid=2524&xml-stylesheet=none
Of course, you are not after XHTML, but some other XML format. But XSLT will do the job.

Resources