Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML patterns #139

Open
AnthonyDGreen opened this issue Jul 12, 2017 · 1 comment
Open

XML patterns #139

AnthonyDGreen opened this issue Jul 12, 2017 · 1 comment

Comments

@AnthonyDGreen
Copy link
Contributor

This builds on proposal #124 "Pattern Matching".

In addition to the new patterns proposed in #124 and #101 I think it would make sense to consider revisiting existing literal/object creation expressions in the language and seeing if we can come up with valuable patterns for them, for example XML. Scala actually has both XML literals and XML pattern matching.

Following the principles for pattern matching established in #124 that pattern syntax should mirror construction syntax so it would look like this:

For Each node in doc.<fragments>
    Select Case node
        Case Match <address type=<%= addressType %>>
                       <first-name><%= firstName %></first-name>
                       <last-name><%= lastName %></last-name>
                   </address>
             When addressType <> "work"
               
            Console.WriteLine($"Contact found! {lastName}, {firstName}")
        
        Case Else
            ...
    End Select
End Select  

It's a bit clunkier than I'd like (as much as XML literals are) but it could be powerful for XML document parsing/processing and would make sure this feature keeps up with other advancements to the language. Also, it's better than XSLT, which is the bare minimum anyone can really ask of life.

@reduckted
Copy link
Contributor

I realize that many legacy applications still use XML, but do we really want to keep adding support for XML when there are far better ways for serializing and transferring data?

It's not like you can't achieve the same thing with some simple System.Xml.Linq stuff:

For Each node In doc.<fragments>
    For Each address In node.<address>.Where(Function(x) x.@type = "work")
        Console.WriteLine($"Contact found! {address.<last-name>.Value}, {address.<first-name>.Value}")
    Next address
Next node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants