2012-01-11 109 views
0

有没有一种方法可以使用Xml为数据库动态创建表和结构?如何在Cakephp中使用XML自动创建数据库的表和结构

因此,使用Xml作为参考生成列。

就像Cakephp中可用的那样?

下面是示例XML,我打算使用:(我没有复制粘贴所有的人,因为它是相当大的)

</dsr_data_agg_stats> 
     <state code="ACT"> 
     <post_code code="2600"> 
      <locality name="DEAKIN"> 
      <dwelling_type code="H"> 
       <typical_value rank="3341/3697">831000</typical_value> 
       <dom score="1" rank="454/5673">56</dom> 
       <discount score="0" rank="779/5673">5%</discount> 
       <acr score="-1" rank="914/5531">59%</acr> 
       <renters score="0" rank="5131/5627">42%</renters> 
       <vacancy score="1" rank="4714/5673">2.61%</vacancy> 
       <yield score="-1" rank="678/3697">3.69%</yield> 
       <som score="1" rank="3915/5144">2.08%</som> 
       <search_dsr score="-3" rank="3578/4009">4.9</search_dsr> 
       <dsr rank="3121/5673">23</dsr> 
       <sr rank="2552/5673">5.8</sr> 
      </dwelling_type> 
      </locality> 
      <locality name="YARRALUMLA"> 
      <dwelling_type code="H"> 
       <typical_value rank="3438/3697">931250</typical_value> 
       <dom score="1" rank="454/5673">56</dom> 
       <discount score="0" rank="779/5673">5%</discount> 
       <acr score="-2" rank="1999/5531">42%</acr> 
       <renters score="0" rank="5131/5627">42%</renters> 
       <vacancy score="1" rank="4714/5673">2.61%</vacancy> 
       <yield score="1" rank="678/3697">4.76%</yield> 
       <som score="0" rank="4333/5144">3.03%</som> 
       <search_dsr score="-3" rank="3277/4009">7</search_dsr> 
       <dsr rank="3121/5673">23</dsr> 
       <sr rank="2552/5673">5.8</sr> 
      </dwelling_type> 

...

回答

0

我正在做类似的东西,但与RSS源。我发现我非常喜欢redis语法,它可以让你根据自己的喜好使用复杂和严格的词汇表,但具有访问任何主要现代数据类型的所有优点,可以平铺在散列表上地图。在很多不同的语言中都有非常易于使用的客户端,但是它归结为思考如何在模式的“操作”“键”值中可靠地构建字符串模式以找到所需内容,如下所示”,其中$表示给定的字符串的variabe组件:

get locality:$id = name 
list locality:dwellings = [dwelling:id, dwelling:id ...] 
map-get dwelling:id 'typical_value' = 'rank: $rank\tvalue: $value' 

我使用PHP直接与Redis的互动,并通过jQuery $。员额异步交互客户端调用服务器端接口,路线命令到redis访问器类。界面非常简单。这里是jQuery方面。

/*QUERY 
*functional programming puts a big emphasis on "wrapping" repetitive tasks inside 
*another function. This one amounts to the same thing as a protocol in 
*Clojure, with the query map acting as the dispatch value that triggers 
*the right method on the server side, recieves and parses the response, 
*and then passes it on to the "body" of the client logic expressed in callback, 
*which causes side effects on the screen. 
*/ 
redgets.query = function(query_map, callback) { 
    $.post(redgets.router, query_map, function(data) { 
    return callback($.parseJSON(data)); 
    }); 
}; 

和示例query_map如下所示:

$response = array(); 
switch ($_POST['method']) { 
case 'locality_by_id': 
    if ($_POST['localityID']) { 
     $response = $this->locality_by_id($_POST['localityID']); 
     break; 
//etc, until 
return json_encode($response); 
} 

其中$这个 - > locality_by_id()是:

{method: 'locality_by_id', localityID: 'locality:1'} 

其中例如PHP的路由器可以与解读您通过predis客户端界面编写的用于触摸redis的查询。

Redis使得随机访问XML文件的速度更快,并且更容易缠绕头部,一旦您将头部缠绕在平面地图上的树形数据结构外面。这意味着,您必须编写一个解析器,将DOM项目转换为适合redis友好的键值对。我相信你会对如何最好地做到这一点有一些想法。一旦你写了一个转换器,反过来也很容易。

(我会添加更多的链接,但垃圾邮件控制sez否)

相关问题