Sunday 15 July 2012

haskell - put xml into a hash table -


I am trying to get the information into a lookup table with an XML file. So far, I am reading whether books can be available and how they can be used. I went with the Hxt and hashtables files here:

  & lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Table & gt; & Lt; Table name = "Namestest 1" & gt; Test1 & lt; / Table & gt; & Lt; Table name = "Namestest 2" & gt; Test2 & lt; / Table & gt; & Lt; / Table & gt;   

I have to add the following:
nametest1, test1
nemetest2, test2
etc ...

  - | We get XML in a hash getTables :: IO (H. hashtable string string) GetTables = do confPath & lt; - getEnv "ENCODINGS_XML_PATH" Doctor & lt; - Run X $ Reading Document [withValidate no] confPath - This is the part that I don't have - I get the process of creating and putting a complete hashtable - getting this XML information which is blocking - I think That is, I can use the following, so I bravelently tagged them on the net. Tag tag = deep (is eelm; gt; & gt; & gt; hedem tag) text = mixer & gt; & Gt; & Gt; GetText   

I gave several examples of similar things, but I did not know how to get the name attribute on each node.

Cheers, Rakwat

Here is an example, which is named after test.xml Reads a file and just adds (print by name, text):

  import text.xml.HXT.Core - | Get the name attribute and the contents of the selected items as a pairAttry and Text :: (Aero XML A) => An XmlTree (string, string) getAttrAndText = getAttrValue "name" - and with the attribute name it's zipped & amp; Amp; GetText-- get node text - | A root table item getTableItem :: (ArrowXml a) = & gt; Under "All" table gets the items. An XmlTree XmlTree getTableItem = deep (name "tables") - a tag & lt; Tables & gt; Search anywhere in the & gt; & Gt; & Gt; Meet children - Get all children of that tag & gt; & Gt; & Gt; HasName "table" - Filter people who have the tag & lt; Table & gt; & Gt; & Gt; & Gt; HasAttr "name" - Filter people who have a feature name - | Main function main = (print = & lt; & lt;) $ runX $ - read results [print] [not with validate] "test.xml" - Read Document & gt; & Gt; & Gt; GetTableItem - Get All Table Items & gt; & Gt; & Gt; GetAttrAndText - Get the attribute 'name' and the text of those nodes   

The pair is built in getAttrAndText The rest of the functions open the file only and select all the tags that are immediate children of a tag Are there. You still want to strip the leading whitespace in the text.

No comments:

Post a Comment