ãXMLããJSONã¸ã®å¤æãã©ããã¹ããããã®ã³ã¡ã³ãæ¬ã«ã¦ãamanoãããããGoogleãGDataã§æ¡ç¨ãã¦ããXML-to-JSONå¤æãæãã¦ããã ãã¾ããã
ããªããä¼¼ããã¨ããã£ã¦ãããªãã¨ã¯æã£ãã®ã§ãããGDataã®æ¹å¼ã¯ãæ®å¿µãªããæã ã®ç®çã«ã¯ä½¿ãã¾ãããä¾ãã°ã次ã®XHTMLæçãèãã¦ã¿ã¾ãã
<p>ãã<em>ã«ã¯</em>ã«ã¯ã«ã¯<br /><em>ã«ã¯</em>ã¨ãããã¾ãã</p>
Catyã®XML-to-XJSONå¤æã使ãã¨æ¬¡ã®ããã«ãªãã¾ãã
@p {"":
["ãã", @em {"" :["ã«ã¯"]}, "ã«ã¯ã«ã¯", @br {"":[]},
@em { "" :["ã«ã¯"]}, "ã¨ãããã¾ãã"]
}
ç¥è¨ï¼ã·ã§ã¼ããã³ãï¼ãèªããã°ãããªãç°¡æ½ã«æ¸ãã¾ãã
@p ["ãã", @em "ã«ã¯", "ã«ã¯ã«ã¯", @br {}, @em "ã«ã¯", "ã¨ãããã¾ãã"]
GDataã®æ¹å¼ã§ã¯ããã®ä¾ãJSONã«å¤æã§ãã¾ãããå¤æã«ã¼ã«ãè£ã£ã¦ç¡çããã«å¤æãã¦ã¿ãã¨ãçµæã¯æ¬¡ã®ã¨ããã
{
"p" : {
"em" : [{"$t" : "ã«ã¯"}, {"$t": "ã«ã¯"}],
"br" : {},
"$t" : "ããã«ã¯ã«ã¯ã«ã¯ã«ã¯ã¨ãããã¾ãã"
}
}
ãã¨ã®XMLæ§é ã¯å£ãã¦ãã¾ããåç¾ä¸å¯è½ã§ããã¨ããäºæ ã§ãGDataæ¹å¼ã®å¤æã«èå³ã¯æ¹§ããªãã£ãã®ã§ãããç¹å®ã®XMLãã¼ã¿ã ãã«å¶éããã°ãGDataæ¹å¼ã¯å¹ççãªå¤æãã§ããã®ã§ãGDataæ¹å¼ãæªããªãã¨æè¿æãç´ãã¾ããã
GDataã®XML-JSONå¤ææ¹å¼
ä¾é¡ã¨ãã¦ã次ã®XMLãã¼ã¿ã使ãã¾ãã
<person gender="male">
<age>26</age>
<hobby>é£ã</hobby>
<hobby>çæ ½</hobby>
<name><family>åæ±</family><given>ãã³å</given></name>
<address type="home">æ±äº¬é½ç®é»åºåç®é»å¤§ç®ç 0-100-99</address>
</person>
GDataã®æ¹å¼ã«å¾ãã¨ãXMLè¦ç´ ã¯JSONãªãã¸ã§ã¯ãã®ããããã£ã«å¤æããã¾ããåºæ¬çãªå½¢ã¯æ¬¡ã®ã¨ããã§ãã
- "ã¿ã°å" : { ï¼å±æ§ã¨åãã¼ãï¼ }
ä¸ã®ä¾ã§ã¯æ¬¡ã®ããã«ãªãã¾ãã
"person" : { ï¼å±æ§ã¨åãã¼ãï¼ }
å±æ§ã¨åãã¼ãã«ã¯æ¬¡ãããã¾ãã
- genderå±æ§
- ageåè¦ç´
- hobbyåè¦ç´ ï¼2ã¤ï¼
- nameåè¦ç´
- addressåè¦ç´
ã¾ããå±æ§ã¯æååå¤ã®ããããã£ã¨ãã¾ãã
"person" : {
"gender" : "male",
ï¼åãã¼ãï¼
}
ageè¦ç´ ã "age" : "26"
ã¨ãã£ã¦ãã¾ãã¨å±æ§ã¨åºå¥ãä»ããªãªããªãã¾ããè¦ç´ ã®ã¨ãã¯ãå¤ãæååã§ã¯ãªãã¦å¿
ããªãã¸ã§ã¯ãã¨ãã¾ãã
"person" : {
"gender" : "male",
"age" : {ï¼ageã®åãã¼ãï¼},
ï¼personã®æ®ãã®åãã¼ãï¼
}
ageã®åãã¼ãã¯ããã¹ããã¼ãã§ããããã¹ããã¼ãã«ã¯ãå±æ§åãè¦ç´ ã¿ã°åã®ãããªååãããã¾ãããããã§ã"$t" ã¨ããç¹å¥ãªååãä¸ãã¦å±æ§ã¨åãããã«è¨è¿°ãã¾ããããã¯ããå 容ããã¹ãã¯ã$t ã¨ããååã®å±æ§å¤ã¨ã¿ãªããã¨è¨ã£ã¦ãããã§ãããã
"person" : {
"gender" : "male",
"age" : {"$t" : "26"},
ï¼personã®æ®ãã®åãã¼ãï¼
}
hobbyè¦ç´ ãåãããã«ããã¨ï¼
"person" : {
"gender" : "male",
"age" : {"$t" : "26"},
"hobby" : {"$t" : "é£ã"},
"hobby" : {"$t" : "çæ ½"},
ï¼personã®æ®ãã®åãã¼ãï¼
}
ãã£ã¨ãããã¯ãã¡ã§ããJSONãªãã¸ã§ã¯ãã«åãååã®ããããã£ãè¤æ°ã¯å ¥ãããã¾ããããããªã¨ãã¯ãå¤ãé åã«ãã¾ãã
"person" : {
"gender" : "male",
"age" : {"$t" : "26"},
"hobby" : [{"$t" : "é£ã"}, {"$t" : "çæ ½"}],
ï¼personã®æ®ãã®åãã¼ãï¼
}
<name><family>åæ±</family><given>ãã³å</given></name>
ã®é¨åã¯æ¬¡ã®ããã§ããã
"name" : {
"family" : {"$t": "åæ±"},
"given": {"$t": "ãã³å"}
}
ãããå ¥ãåã«ãã¦ã¯ãè¾¼ãã¨ï¼
"person" : {
"gender" : "male",
"age" : {"$t" : "26"},
"hobby" : [{"$t" : "é£ã"}, {"$t" : "çæ ½"}],
"name" : {
"family" : {"$t": "åæ±"},
"given": {"$t": "ãã³å"}
},
ï¼personã®æ®ãã®åãã¼ãï¼
}
<address type="home">æ±äº¬é½ç®é»åºåç®é»å¤§ç®ç 0-100-99</address>
ã¯ãtypeã¨ããåã®å±æ§ã¨ã$tã¨ããåã®å±æ§ãããããã«æ±ãã°ããã®ã§ï¼
"person" : {
"gender" : "male",
"age" : {"$t" : "26"},
"hobby" : [{"$t" : "é£ã"}, {"$t" : "çæ ½"}],
"name" : {
"family" : {"$t": "åæ±"},
"given": {"$t": "ãã³å"}
},
"address" : {
"type" : "home",
"$t" : "æ±äº¬é½ç®é»åºåç®é»å¤§ç®ç 0-100-99"
}
}
JSONã§ã¯ãããããã£ã ãã§ã¯ãã¼ã¿ã¨èªããããªãã®ã§ãåä¸ã®ããããã£ãæã¤ãªãã¸ã§ã¯ãã®å½¢ã«ãã¾ãã
{
"person" : {
"gender" : "male",
"age" : {"$t" : "26"},
"hobby" : [{"$t" : "é£ã"}, {"$t" : "çæ ½"}],
"name" : {
"family" : {"$t": "åæ±"},
"given": {"$t": "ãã³å"}
},
"address" : {
"type" : "home",
"$t" : "æ±äº¬é½ç®é»åºåç®é»å¤§ç®ç 0-100-99"
}
}
}
ã¯ããã§ããããã
ã©ã®ãããªXMLãã¼ã¿ãªãå¤æã§ããã®ã
XMLè¦ç´ ã®å 容ã¢ãã«ã¯ã次ã®3種ã«åé¡ã§ãã¾ãã
- è¦ç´ å 容ã¢ãã« -- åãã¼ãã¨ãã¦è¦ç´ ãã¼ãããåºç¾ããªã
- ããã¹ãå 容ã¢ãã« -- ï¼DOMæ£è¦åã®å¾ã§ï¼åãã¼ãã¨ãã¦ãã 1ã¤ã®ããã¹ããã¼ãããåºç¾ããªã
- æ··åå 容ã¢ãã« -- åãã¼ãã¨ãã¦è¦ç´ ãã¼ãã¨ããã¹ããã¼ããæ··ããå¯è½æ§ããã
GDataæ¹å¼ã§ã¯ãæ··åå 容ã¢ãã«ã®è¦ç´ ã¯JSONã«å¤æã§ãã¾ãããè¦ç´ å 容ã¢ãã«ã¾ãã¯ããã¹ãå 容ã¢ãã«ã§ããè¦ç´ ï¼ã®åï¼ãå¤æ対象ã¨ãªãã¾ããããã«ãåè¦ç´ ã®åºç¾é åºã«æå³ãããã¨é åºæ å ±ã失ãããã®ã§ãã¡ã§ããå¤æå¯è½ã§ããæ¡ä»¶ãã¾ã¨ããã¨æ¬¡ã®ããã«ãªãã¾ãã
- è¦ç´ ã®åãã¼ãã¯åä¸ã®ããã¹ããã¾ãã¯ããã¤ãã®è¦ç´ ãã¼ãã§ãããããã¹ãã¨è¦ç´ ãæ··ãããã¨ã¯ãªãã
- è¦ç´ ã®å 容ãåè¦ç´ ã®åã§ããã¨ãããããã®åè¦ç´ ã®åºç¾é åºã«æå³ããªãã
ãã®æ¡ä»¶ãæºããXMLãã¼ã¿ã¯ãã£ããå¤ãã®ã§ãå®ç¨ä¸ã®é©ç¨ç¯å²ã¯çãã¯ãªãã§ããããã§ã¯ããã®å¤æå¯è½æ§ã®æ¡ä»¶ãæºããã°ãä½ãèããªãã¦ãå¤æã§ããã§ããããï¼ å®ã¯ããã§ããªããã§ãã
空ç½é¡ã®æ±ããã©ãããã
XMLå¦çãããã¨ãã«æ¯åº¦é ãçãã®ã空ç½é¡ï¼ãã¯ã¤ãã¹ãã¼ã¹ï¼ã®æ±ãæ¹ã§ããã¤ã³ã¹ã¿ã³ã¹ã ããè¦ã¦ãã¦ã¯ã空ç½é¡ã ãã®ããã¹ããæ¨ã¦ã¦ãããã©ãããµãããªããããªãã®ã§ãå®å ¨ã®ããã«ã¯ä¿åããããããã¾ãããxml:spaceå±æ§ãå¦çã®ãã³ãã«ãªãã¾ãããxml:spaceã常ã«æå¾ ã§ããããããããã¾ããã
ä¾é¡ã§ãã£ã次ã®XMLã¤ã³ã¹ã¿ã³ã¹ãDOMããªã¼ã«å±éããã¨ã空ç½é¡ã ãã®ããã¹ããã¼ããããããã§ãã¾ãã
<person gender="male">
<age>26</age>
<hobby>é£ã</hobby>
<hobby>çæ ½</hobby>
<name><family>åæ±</family><given>ãã³å</given></name>
<address type="home">æ±äº¬é½ç®é»åºåç®é»å¤§ç®ç 0-100-99</address>
</person>
ã¨ãªãã¨ãå 容ã¢ãã«ã¯æ··åå 容ã¢ãã«ã¨ãªããGDataæ¹å¼ã§ã¯å¤æä¸å¯è½ã¨ãªãã¾ãã
ããããããã空ç½é¡ãæ¨ã¦ã¦ãã¾ããã¨ã«ããã¨ã©ããªãã§ããããã次ã¯ãããªãã£ããªã³ã¿ã®è¨å®ãã¡ã¤ã«ã ã¨ãã¾ãã
<prettyPrint>
<indentString> </indentString>
<delimiter> </delimiter>
<terminator></terminator>
</prettyPrint>
ãã®è¨å®ã®æå³ã¯ï¼
- ã¤ã³ãã³ãã«ã¯éé空ç½ï¼0x20ï¼4ã¤ã使ã
- åºåãè¨å·ã«ã¯éé空ç½1ã¤ã使ã
- çµç«¯è¨å·ã«ã¯æ¹è¡ã2ã¤ä½¿ã
空ç½é¡ãåé¤ãã¦ãã¾ãã¨ãè¨å®æ å ±ãã¾ã£ãã失ããã¦ãã¾ãã¾ãã
ãããã©ãããã®ï¼ ã£ã¦è©±ã¯ãä½å¹´ãåã«ä½åº¦ãæ¸ãããããã¹ã£ãããããã¨ããããã§ãåã¨ãã¦ã¯é£å·æ°å³ãæ°ãåãããæ¸ãããããã¾ããããç¹ã«ãã¾ãæ¹æ³ããããããããªãã¦ãå¦çç³»ã«ç©ºç½å¦çã®æ¹æ³ãå¥éä¸ãããããªãã®ã§ãã