views:

246

answers:

9

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 :)

+4  A: 

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.

Joey
subject says 'programming languages'
nixau
XSLT _is_ a programming language - it's Turing-complete (http://en.wikipedia.org/wiki/Turing_complete).
NickFitz
yep, my bad. I actually ment 'declarative'. I've updated my question
nixau
A: 

Depends how you mean by deeply integrated? .net comes with an XML namespace and various classes for dealing with XML documents...

Paddy
It means what subject says. Native integration does not imply that you're required to use a set of classes to perform simple/trivial operations on xml document.
nixau
+10  A: 

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"&gt;
            <%= From country In XDataSet Select <Country Code=<%= country.CountryISO %> Name=<%= country.CountryName %>/> %>
        </Countries>

    Return XDoc.ToString
End Function
Dror Helper
I loved it when they introduced this in VB.NET 9... finally something to show to C# developers and make them say, "actually, that's would be quite nice to have in C#..."
AakashM
+2  A: 

Groovy and Scala have XML literal support, though I think this is generally a really stupid idea.

pmf
+2  A: 

javascript,see here

E.T
A: 

I'd go with groovy since it integrates best with Java.

Geo
A: 

XQuery ? From the linked article:

XQuery provides the means to extract and manipulate data from XML documents or any data source that can be viewed as XML, such as relational databases or office documents.

It supports for-loops, whiles, let, ordering etc.

Brian Agnew
yes, but it is rather declarative language than algorithmic one
nixau
:) I don't dislike them, they're cool, but the question was about algorithmic languages like Java...
nixau
+1  A: 

Flex and Action Script.

Geek
+3  A: 

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.

kret
this seems to be the most clear answer. Thanx you.
nixau