HaloO,

James Fuller wrote:
On Nov 29, 2007 1:15 PM, Luke Palmer <[EMAIL PROTECTED]> wrote:
So to bring some perspective back into this discussion, I'd like to
ask you, what would it mean to you for there to be an XML type in
core?  That is,
from a user's perspective, disregarding implementation of the
language?  What would you be able to do with it that you couldn't do
if it were a module

Here are my perception of the discussion so far. We must distinguish
two fundamentally different things. One is the feature set of the
language itself and the other are applications expressed in that set.
Since one key aspect of Perl 6 is parsing it should be a strict superset
of XML! XML is all about machine friendly parsing---beat me if that is
over simplified but I'm looking at it from a very abstract point of
view. Perl 6 addresses a much harder task: human friendly parsing ;)


(arguments such as "use it without putting 'use XML::Foo' at the top"
considered valid)?

This single line is all it boils down to in the end.


well, if my previous posts didn't attract flames.... this post certainly will ;)

I do not intend to flame. And I'm not an XML expert. But I try to map
your ideas to language features of Perl 6 as they stand right now and
how I remember them.


Here are some examples of psuedo syntax I would find useful (which I
have borrowed from things like XQuery, e4X, etc);

---------------------------------
declaring some xml in one's perl program;
---------------------------------

my $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>;

Shouldn't that be a job for a here doc?

my $sales = q:to'XML-END'
    <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>
XML-END

But assuming you a XML::sales type this could just be

my XML::sales $sales( ... constructor syntax anyone? ...);


however this leads to some 'other thoughts, like how does perl and xml
play nice together....

what about;

my $html  = <html><head/><body>
    <span>
      <h1>{ $sometitlevar }</h1>
      <ul>
      {

loop ($counter = 1; $counter < 20; $counter++) {
     <li>Try to count electric sheep . . . </li>;
}

      }
      </ul>
    </span>
</body></html>

If you consider that nice. The thing you try to achieve is
handle XML as a programming language which it hardly is and
compensate with the programming constructs from perl. The
better approach is to see XML as typed data that is parsed
from files and that you can manipulate like other data and
write it back.

E.g. a validation run might simply be the condition

    if ($doc does XML::SomeDTD) {...}


when it comes to manipulating XML, there are a few axioms...

---------------------------------
How to Address parts of an XML document variable ?
---------------------------------

It is common to want to address a portion of an XML document

    my $select_li_elements  = $html.html.body.span.ul ;

this syntax is ok (actually I do not like this approach), but I like
my 'scanability' to be in xpath form ala:

    my $select_li_elements  = $html[/html/body/span/ul/li];

Perl 6 has got full-blown namespace support so this might actually
be

  my $select_li_elements  = $html[html::body::span::ul::li];

Actually I think the hash sigil is more in the spirit of XML so
it should read %html<html::body::span::ul::li>.

and then u have the expressive power of xpath inside of these brackets.

What if you had a XPath that does namespace?


so when declaring a var as xml, it would be this

my $data is XML;

Obviously.


( as an aside, is there any concept of the native types, Scalar,
Array, Hash being in a different namespace then all the other symbols
e.g. could I override Scalar type ?)

There is no difference between native and non-native types. Perl 6 has
a well defined syntactical slot for type information and the convention
that the names start with a capital letter.


---------------------------------
How do I update an XML document variable ?
---------------------------------

Here are a few edit type examples reusing the XPATH syntax introduced earlier;

Without going into syntax details the manipulation should be through
the same language interface that is available for other data structures.


---------------------------------
And what about validation?
---------------------------------

Perhaps one would like to be able to decide if this xml must be
checked for validaty against some schema technology (DTD and relaxNG
as basic) .... are there any 'adjectives when declaring a type ... I
guess I am suggesting a new sigil enforcing an XML context ;0

It's hardly worth a sigil. Validity checking is a "simple" type check.


then there is the 'processing' XML bit .....

---------------------------------
Iterating through XML
---------------------------------

should print out the value of each div contained in html

for $myxmlvar[/html/body/div]]{
    print; # prints $_, the current loop variable
}

How about

  for grep html::body::div $myxmlvar {...}


Regards, TSa.
--

You know, it would be sufficient to really understand the electron.
                                      --- Albert Einstein

Reply via email to