정원희's blog, season 2006 start! |
딱따구리
http://blog.naver.com/nobodyuknow/100028605773|
| Pattern | XML | JSON | Access |
| 1 |
| "e": null | o.e |
| 2 | text | "e": "text" | o.e |
| 3 |
| "e":{"@name": "value"} | o.e["@name"] |
| 4 | text | "e": { "@name": "value", "#text": "text" } | o.e["@name"] o.e["#text"] |
| 5 | text text | "e": { "a": "text", "b": "text" } | o.e.a o.e.b |
| 6 | text text | "e": { "a": ["text", "text"] } | o.e.a[0] o.e.a[1] |
| 7 | text text | "e": { "#text": "text", "a": "text" } | o.e["#text"] o.e.a |
출처 : http://cafe.naver.com/webagencyalone.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=25
xml -> json
1. [패턴1]
<?xml version="1.0" encoding="Shift_JIS" ?>
<rss>
<channel>
<title>111</title>
<link>222</link>
</channel>
</rss>
json으로 바꾸면...
{
rss: {
channel: {
title: "111",
link: "222"
}
}
}
javascript에서 json변수의 요소를 가저올때(json변수명이 data일 경우)
data.rss.channel.title ---->111 다음과 같이 써도 동일 data["rss"]["channel"]["title"]
data.rss.channel.link ---->222 다음과 같이 써도 동일 data["rss"]["channel"]["link"]
2.[패턴2]
<?xml version="1.0" encoding="Shift_JIS" ?>
<rss>
<channel>
<title>111</title>
<title>222</title>
<link>333</link>
</channel>
<channel>
<title>444</title>
<title>555</title>
<link>666</link>
</channel>
</rss>
json으로 바꾸면...
{
rss: {
channel: [
{
title: [
"111",
"222"
],
link: "333"
},
{
title: [
"444",
"555"
],
link: "666"
}]
}
}
data.rss.channel[0].title[0] --->111 다음과 같이 써도 동일 data["rss"]["channel"][0]["title"][0]
data.rss.channel[1].link --->666 다음과 같이 써도 동일 data["rss"]["channel"][1]["link"]
3.패턴[3]
<?xml version="1.0" encoding="Shift_JIS" ?>
<rss version="2.0">
<channel>
<title>111</title>
<link opt1="opt1111" opt2="opt222">222</link>
</channel>
</rss>
json으로 바꾸면...
{
rss: {
version: "2.0",
channel: {
title: "111",
link: {
opt1: "opt1111",
opt2: "opt222",
"#text": "222"
}
}
}
}
data["rss"]["channel"]["link"]["#text"] --->222
data.rss.channel.link.#text 로 하면...에러발생...
#가 파싱할때 예약어인거 같음..
4.패턴4
<?xml version="1.0" encoding="Shift_JIS" ?>
<rss version="2.0">
<channel>
<title aaa="111"/>
<asdfsdf/>
</channel>
</rss>
json으로 바꾸면...
{
rss: {
version: "2.0",
channel: {
title: { aaa: "111" }
}
}
}
5.아래와같이 동일한 옵션명이 있으면 에러
<bb aa="11" aa="22"/>
옵션명에 :를 넣는경우는 xmlns로 정의된경우만 가능...이외에는 에러남...
아래와 같은 경우 옵션명에 :를 넣음
<?xml version="1.0" encoding="utf-8" ?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Borders/>
<Font ss:FontName="MS Pゴシック" x:CharSet="128" x:Family="Modern" ss:Size="11"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Workbook>
댓글을 달아 주세요