dummy-link

XMLDict

XMLDict implements a simple Associative interface for XML documents.

Readme

XMLDict.jl

XMLDict implements an Associative interface (get(), getindex(), haskey()) for reading XML elements and attributes. Requires EzXML.jl.

Build Status

Examples

Extract the content of a single tag...

xml = parse_xml("""

    
        http://queue.amazonaws.com/123456789012/testQueue
    

""")

@test xml["CreateQueueResult"]["QueueUrl"] == "http://queue.amazonaws.com/123456789012/testQueue"

Extract an attribute from a tag by using a :symbol as key...

xml = parse_xml("""

  

""")

@test xml["bookstore"]["book"][:category] == "COOKING"

Extract a list of tag content...

xml = parse_xml("""

  
    quotes2006-02-03T16:45:09.000Z
    samples2006-02-03T16:41:58.000Z
  

""")

@test [b["Name"] for b in xml["Buckets"]["Bucket"]] == ["quotes", "samples"]

Extract a dictionary of <Name>, <Value> tags content...


xml = parse_xml("""

  
    VisibilityTimeout30
    CreatedTimestamp1286771522
    MaximumMessageSize8192
    MessageRetentionPeriod345600
  

""")

d = [a["Name"] => a["Value"] for a in xml["GetQueueAttributesResult"]["Attribute"]]

Dict with 4 entries:
  "MessageRetentionPeriod" => "345600"
  "MaximumMessageSize"     => "8192"
  "VisibilityTimeout"      => "30"
  "CreatedTimestamp"       => "1286771522"

Convert entire XML document to a Julia Dict...

xml_string="""


  
    
        Everyday Italian
    
    Giada De Laurentiis
    2005
    30.00
    The bold word is not italic.
  
  
    Harry Potter
    J K. Rowling
    2005
    29.99
    John Smith]]>
    Click right here for foobar.
  
  
       hello!
  

"""
d = xml_dict(xml_string)

Dict(
    :version=>"1.0",
    :encoding=>"UTF-8",
    "bookstore"=>Dict(
        :brand=>"amazon",
        "book"=>[
            Dict(
                :category=>"COOKING",
                :tag=>"first",
                "title"=>Dict(:lang=>"en",""=>"Everyday Italian"),
                "author"=>"Giada De Laurentiis",
                "year"=>"2005",
                "price"=>"30.00",
                "extract"=>Dict(
                    :copyright=>"NA",
                    ""=>["The ",Dict("b"=>"bold")," word is ", Dict("b"=>Dict("i"=>"not"))," ",Dict("i"=>"italic"),"."])
            ),
            Dict(
                :category=>"CHILDREN",
                "title"=>Dict(:lang=>"en",""=>"Harry Potter"),
                "author"=>"J K. Rowling",
                "year"=>"2005",
                "price"=>"29.99",
                "foo"=>"John Smith",
                "extract"=>["Click ",Dict("a"=>Dict(:href=>"foobar.com",""=>["right ",Dict("b"=>"here")]))," for foobar."]
            )],
        "metadata"=>Dict("foo"=>"hello!")
    )
)

First Commit

01/03/2016

Last Touched

15 days ago

Commits

70 commits