Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any programming languages that support xml natively? [closed]

If there are any then how deeply is xml integrated into language? What primitives are used to manipulate xml document?

PS. I'm not interested in declarative languages such as SQL, XPath, XSLT :)

like image 686
nixau Avatar asked Jun 19 '09 09:06

nixau


3 Answers

VB.NET 9.0 has XML literals which seems like what you're looking for. This example taken from Imran Shaik blog

    <WebMethod()> _
Public Function AllCountriesUsingXMLLiterals() As String

    Dim sud As New CountryDataSetTableAdapters.CountryTableTableAdapter

    Dim XDataSet As New CountryDataSet.CountryTableDataTable

    sud.Fill(XDataSet)

    Dim XDoc = _
        <Countries xmlns="http://tempuri.org/Schema/Countries">
            <%= From country In XDataSet Select <Country Code=<%= country.CountryISO %> Name=<%= country.CountryName %>/> %>
        </Countries>

    Return XDoc.ToString
End Function
like image 81
Dror Helper Avatar answered Sep 30 '22 15:09

Dror Helper


Flash's ActionScript 3.0 and JavaScript (ECMAScript languages) are also integrated with XML by E4X.
So code looks something like this (altough this is a simple example and cooler stuff is possible):

var sales = <sales vendor="John">
    <item type="peas" price="4" quantity="6"/>
    <item type="carrot" price="3" quantity="10"/>
    <item type="chips" price="5" quantity="3"/>
  </sales>;

alert( sales.item.(@type == "carrot").@quantity );
alert( sales.@vendor );
for each( var price in sales..@price ) {
  alert( price );
}

Here are Adobe's docs for working with XML in AS3.0.

like image 30
Andrzej Undzillo Avatar answered Sep 30 '22 17:09

Andrzej Undzillo


Powershell has some niceties in dealing with XML, mainly that a node gets dynamic properties representing its sub-nodes. So given the XML

<foo>
  <bar/>
  <bar/>
</foo>

an XML object created from this has a "foo" property and the object returned by that has a "bar" property.

> $x=[xml]"<foo><bar moo='meh'/><bar meow='bleh'/></foo>"
> $x.foo

bar
---
{bar, bar}

> $x.foo.bar[0]

moo
---
meh

> $x.foo.bar[1]

meow
----
bleh

Very handy at times.

like image 27
Joey Avatar answered Sep 30 '22 16:09

Joey