반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

이번 대선 결과를 보고 다시 깊이 생각해 봅니다.


왜 이럴까?

정의는 천천히 올 수도 있다고 누군가가 얘기 했다던데...


유튜브를 보다가 한달 전 박정희에 대한 미국 의회의 분석 자료인 프레이저 보고서를 냈던 민족문제 연구소의 비디오들을 몇개 봤습니다.


박정희편인 프레이저 보고서 비디오는 부록이었더라구요. (스페셜 에디션)


원래는 백년 전쟁으로 일본 제국주의 시대에 대항했던 독립군의 정신으로 해방후에도 계속되는 친일파들의 치부에 저항하는 그런 의미에서 만든 비디오더라구요.


그리고 민족 문제 연구소가 생기게 된 이유를 알게 됐습니다.


평생 가난하게 사시면서 친일 역사를 연구하셨던 임종국 선생의 뜻을 기리기 위해 만든 단체가 민족문제 연구소더라구요.

친일의 역사를 연구하다가 일제시대 당시 신문에서 자신의 아버지 이름을 발견한 임종국 선생..

아버지를 찾아가 여쭙니다.

"아버지 이름을 뺄까요?"

그 아버지는 한참을 생각하다가 말씀 하셨답니다.

"넣어라. 내 이름이 빠지면 그 책은 죽은 책이다."


친일파, 독재자의 딸인 분도 이런 자세로 국정을 펴 나갈 수 있을까요?

그렇지 않을 것 같습니다.

그래서 절망감이 더 큽니다.


절망 끝에 포기가 오지 않도록 하기 이해 민족문제 연구소의 비디오를 봤습니다.



제가 할 수 있는 일은 제 일을 열심히 하면서 살아가는 것이고 또 저를 대신해서 역사를 바로 세우는데 모든 것을 바치시는 이런 분들께 지지의 의사를 표시하는 것 뿐입니다.


저는 민족 문제 연구소의 활동을 지지 합니다.



반응형

Ajax로 툴바 insert 하기

2012. 12. 25. 19:40 | Posted by 솔웅


반응형
Insert toolbars by Ajax




자바스크립트로 footer toolbar를 다이나믹하게 생성하는 대신 Ajax로 서버로부터 HTML 코드를 다운받아서 insert 해 보겠습니다.


Insert a footer toolbar by Ajax


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

   <p> Window content </p>

  </div>

</div>


</body>

</html>


<script>


$.ajax (

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

    $("#home").append (response);

    

    $("#home").fixHeaderFooter ();

  }

}); 


</script>


<div>사용한 fixHeaderFooter () method call 을 잘 보세요. 이렇게 함으로서 data-position="fixed" attribute를 search 하고 거기에 따라 포지션을 정하도록 하는 겁니다. (여기서는 화면의 bottom 부분에 위치하게 되죠)


action.php file


<?
$html = "";
$html .= "<div id=footer class='ui-bar-e ui-footer' data-position=fixed>";
$html .=   "<h1 class=ui-title>Footer part</h1>";
$html .= "</div>";
echo utf8_encode ($html);

?>


action28.php

tistory565_01.html


툴바는 ui-bar-e and ui-footer CSS classes들에서 꾸며줍니다. 그리고 자바스크립트 코드내에서 fixHeaderFooter () method에 의해
data-position="fixed" attribute가 사용되게 될 거구요. 또한 내용을 중앙으로 맞추기 위해 <h1> element를 사용해 ui-title class를 사용하도록 합니다.






반응형


반응형
Turning an HTML element into a jQuery Mobile toolbar



jQuery Mobile 에 의해 변환된 이전 글 예제의 HTML 코드입니다.





header toolbar 에는 ui-bar-a and ui-header CSS classes 들이 있습니다. 그리고  footer toolbar에는 ui-bar-a and ui-footer classes 들이 있습니다.
<h1> element는 각 아이템들 마다 들어있고 text를 가운데로 보내는 ui-title class 가 있습니다. ui-bar-a class는 디폴트 theme 과 연결 돼 있습니다.(여기서는 a theme)

이 툴바들 중 하나에 data-theme attribute를 설정한다면 ui-bar-a class는 해당되는 클래스로 replace 될 겁니다.(eg ui-bar-e for the "e" theme)


반응형


반응형

툴바를 생성하는 것은 jQuery method들을 사용합니다. 그리고 별도의 utility method들도 jQuery Mobile에 의해 추가 됐습니다. 예를 들어 네비게이션 바의 관리를 좀 더 용이하게 하기 위해 navbar () method를 추가했죠. Navigation bars 들은 표준 navbar component와 연계 돼 있습니다.



Dynamically create a toolbar


툴바에는 두가지 타입이 있습니다. 바로 header (top of the window) and footer (bottom of the window) 가 있죠. toolbar를 dynamic  하게 생성하는 footer typeheader toolbars 들은 HTML 안에 포함이 되게 되는데요 header toolbars 에는 이전 페이지로 돌아가도록 하는 Back button 이 있을 수 있습니다.


Dynamic creation of a footer toolbar


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

   <p> Window content </p>

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<div data-role=footer data-position=fixed>";

html +=   "<h1> Footer part </h1>";

html += "</div>";


$("#home").append (html);


</script>


tistory563_01.html






반응형


반응형

이제 대선도 끝났고..

한국 소식 보다 제가 살고 있는 지역 소식에 더 관심을 가지려고 합니다.


오늘은 Providence Journal 인터넷 판에 로드 아일랜드의 일자리에 대한 기사가 탑으로 실렸네요.




Reinvent RI: Where the young people go


December 23, 2012 9:53 am
By G. Wayne Miller



PROVIDENCE, R.I. -- Lauren Lapolla, 26, has traveled to Italy, Ireland, Belgium and France. During college, she spent a semester in England. After graduation, she found a job in Washington, working for an Ohio congressman, which brought her into her chosen field, public policy. She had a steady paycheck. She made many friends. Life was good. Two years ago, while visiting her parents at the family's Narragansett summer place, she decided to quit her job.


Lauren Lapolla, 26 는 이태리, 아일랜드, 벨기에 그리고 프랑드 등을 여행해 봤다. 대학생활 동안 한 학기를 영국에서 보내기도 했다. 졸업 후 그녀는 워싱턴에 일자리를 얻었다. 그녀가 공공정책 분야와 관련된 일자리를 찾았었는데 오하이오 의원실에서 근무하는 기회를 잡은 거였다. 수입도 안정적이었다. 친구들도 많이 만들고 생활은 좋았다. 2년 후, 여름에 부모를 보려고 부모가 사는 Narragansett 을 방문했을 때 일을 그만 두기로 마음 먹었다.


The Providence Journal / Bob Breidenbach

Lauren Lapolla, a health-care policy specialist in the office of Lt. Gov. Elizabeth Roberts, is an Ocean State native and decided to return to R.I. after college and a stint in D.C. But Rhode Island's poor economy has prompted some young people to leave their native state, despite their desire to stay. See more photos.



"I need to go back," she told her boss in Washington. She wanted to return to the state where she was born and raised.

She did not have a job waiting in Rhode Island, which in 2010 had entered the third year of a recession, with double-digit unemployment and an economy undergoing a painful transition from traditional manufacturing to an uncertain future.

"It was a calculated risk," Lapolla says. "And it was terrifying."

But the emotional pull was stronger than fear.

Four Rhode Island natives in their 20s who recently shared their stories struck a common theme: the Ocean State was a desirable place to grow up and remains a terrific place to live. But one way or another, their home state's economy has proved decisive in where they have planted their adult roots.


"고향으로 돌아가야 겠습니다. " 그녀는 워싱턴의 상관에게 말했다. 그녀가 태어나고 자란 주로 돌아가기를 원한거였다. 로드 아일랜드에 그녀가 일할 일자리가 정해진것은 아니었다. 2010년은 경제 불황이 일어난지 3년째 되는 해였다. 실업률이 두자리 숫자였고 경제상황은 안 좋았다. 전통적인 생산직 일자리부터 모두 미래가 불투명했다.

"그 결정은 확실히 리스크를 감수해야 했어요. 아주 겁났었죠." 라고 Lapolla 는 말한다.

하지만 그 두려움 보다 그리움이 더 앞섰다.

로드 아일랜드 출생의 20대가 최근 그들의 공통의 주제에 대해 얘기를 나눴다. 이 Ocean State (로드 아일랜드 주의 별명)는 자라기에도 좋은 곳이고 여생을 보내기에 정말 훌륭한 곳입니다. 그리고 그들은 어떠한 이유로 그들의 성년기를 이곳에서 보내기로 결정을 했습니다.


IN THE PAPER (종이판 신문)

SUNDAY: We profile four 20-something Rhode Island natives who love the Ocean State. But one way or another, the state’s economy has proved decisive in where they've planted their adult roots. A1.

4명의 로드아일랜드 출신이면서 이곳에서 살고 있는 20대를 만나봤습니다. 그리고 그들은 나름대로의 이유로 이곳에서 성년기를 뿌리 내리겠다고 결심했습니다. A1



======= o ============ o ============= o ===========


어제 기사에는 작년에 로드 아일랜드를 떠난 사람이 들어온 사람들보다 훨씬 더 많아는 기사가 났습니다. 그리고 떠난 사람들의 평균 수입이 들어온 사람들의 평균 수입보다 훨씬 더 높다는 통계도 소개 했구요.

로드 아일랜드의 경제 상황이 안 좋은 인식이 너무 퍼지니까 지역 신문에서 떠나지 않고 이곳에 계속 살고 있는 젊은 이들을 소개하는 기획 기사를 준비 했나 봅니다.

댓글을 보니까 이곳 로드 아일랜드가 타 주에 비해서 세금이나 공과금이 너무 비싸다는 불만의 글 들이 많네요.


반응형

accordion menu 생성 예제들

2012. 12. 23. 22:20 | Posted by 솔웅


반응형
Examples of manipulation of accordion menus



Load the contents of an accordion menu by Ajax


메뉴를 오픈할 때 Ajax에 의해 각 accordion menu 의 내용을 retrieve 하는 예제를 만들겠습니다. 만약 현재 content 가 empty 일 경우 retrieve 됩니다. 그러니까 매번 메뉴가 open 될 때마다 이 로직이 동작하는 건 아니죠.


Get the contents of the accordion menus by Ajax


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <div id=id1 data-role=collapsible data-collapsed=true>

      <h1>Menu 1 : Click to open / close</h1>

    </div>

    <div id=id2 data-role=collapsible data-collapsed=true>

      <h1>Menu 2 : Click to open / close</h1>

    </div>

  </div>

</div>


</body>

</html>


<script>


$("#id1, #id2").bind ("collapsiblecreate", function ()

{

  $("a.ui-collapsible-heading-toggle", this).bind ("click", function (event)

  {

    var h1 = $(this).closest ("h1");

    var content = h1.siblings (".ui-collapsible-content");

    var div = $(this).closest (".ui-collapsible");

    if (content.is (".ui-collapsible-content-collapsed") && 

        $.trim (content.html ()) == "")

    {

      $.ajax (

      

        url : "action.php", 

        data : { menu : div.attr ("id") },

        complete : function (xhr, result)

        {

          if (result != "success") return;

          var response = xhr.responseText;

          $(content).append (response);

        }

      });     

    }

  });

});


</script>


각 메뉴는 HTML 안에 내용이 비어져 있는 상태로 생성됩니다. 그리고  ui-collapsible-heading-toggle class 의 <a> element 있어서 menu 타이틀을 클릭 할 수 있습니다. 이 element 에서 content (of ui-collapsible-content class) 에 해당하는 <div> element retrieve 하기 위해 DOM 을 살펴 보게 되죠. 그리고 나서 <div>는 메뉴 타이틀과 content 를 포함하게 됩니다. 이 때 menu 의 id 로 접근을 하게 됩니다.


또한 메뉴가 close 된 상태인지 그리고 content 가 empty 인지 아닌지도 알아낼 수 있습니다. Ajax call 은 메뉴가 close 상태 이면서 empty인 상태에서만 만들어 지거든요. ui-collapsible-content-collapsed CSS class 가 있으면 content 가 close 인 상태라는 것을 기억해 두세요. 그 클래스가 없으면 open 인 상태 입니다.


action.php file


<?
$menu = $_REQUEST["menu"];

$html = "";
if ($menu == "id1")
{
  $html .=   "<p> Paragraph 1.1 </p>";
  $html .=   "<p> Paragraph 1.2 </p>";
  $html .=   "<p> Paragraph 1.3 </p>";
}
else
{
  $html .=   "<p> Paragraph 2.1 </p>";
  $html .=   "<p> Paragraph 2.2 </p>";
  $html .=   "<p> Paragraph 2.3 </p>";
}
echo utf8_encode ($html);
?>


action27.php

tistory561_01.html


Dynamically change the accordion menu title


The accordion menu title is currently fixed. It is possible to dynamically change, eg change the title as the menu is open or closed.


Change the menu title as the menu is open or closed


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <div id=id1 data-role=collapsible>

      <h1>Menu: closed</h1>

      <p> Paragraph 1.1 </p>

      <p> Paragraph 1.2 </p>

      <p> Paragraph 1.3 </p>

    </div>

    <div id=id2 data-role=collapsible>

      <h1>Menu: closed</h1>

      <p> Paragraph 2.1 </p>

      <p> Paragraph 2.2 </p>

      <p> Paragraph 2.3 </p>

    </div>

  </div>

</div>


</body>

</html>


<script>


$("#id1, #id2").bind ("collapsiblecreate", function ()

{

  $("a.ui-collapsible-heading-toggle").bind ("vclick", function (event)

  {

    var h1 = $(this).closest ("h1");

    if (h1.is (".ui-collapsible-heading-collapsed")) 

      $("span.ui-btn-text", h1).first ().text ("Menu: open");

    else 

      $("span.ui-btn-text", h1).first ().text ("Menu: closed");

  });

});


</script>


tistory561_02.html


menu title은 ui-btn-text class<span> element 에 insert 됩니다. 이것은  title (here <h1>). element 안에 위치하게 되죠. title 안에 여러개의 <span> elements (class ui-btn-text)가 있을 수 있습니다.이 content 는 jQuery 의 text () method에 의해 modify 됩니다.


Producing an effect at the opening and closing the accordion menu


jQuery 를 사용해서 open/closed 에 대해 visual effect를 줄 수 있습니다.  예를 들어 open 할 떄 show (1000)효과를 주고 close 할 때 hide (1000)효과를 줄 수 있습니다.


Effect at the opening and closing accordion menus


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <div id=id1 data-role=collapsible data-collapsed=true>

      <h1>Menu 1: Click to open / close</h1>

      <p> Paragraph 1.1 </p>

      <p> Paragraph 1.2 </p>

      <p> Paragraph 1.3 </p>

    </div>

    <div id=id2 data-role=collapsible data-collapsed=true>

      <h1>Menu 2: Click to open / close</h1>

      <p> Paragraph 2.1 </p>

      <p> Paragraph 2.2 </p>

      <p> Paragraph 2.3 </p>

    </div>

  </div>

</div>


</body>

</html>


<script>


$("#id1, #id2").bind ("collapsiblecreate", function ()

{

  $("a.ui-collapsible-heading-toggle").bind ("vclick", function (event)

  {

    var h1 = $(this).closest ("h1");

    var content = h1.siblings (".ui-collapsible-content");

    if (content.is (".ui-collapsible-content-collapsed")) content.show (1000);

    else content.hide (1000);

  });

});


</script>


tistory561_03.html


각 accordion menu 의 title 부분을 클릭할 때 이것을 handle 할 수 있습니다. 특히 title 안에 <a> link 가 있을 때요. 이 <a> link를 통해서 우리는 ui-collapsible-content class의 <div> element 와 연관된 메뉴의 content를 얻기 위해 DOM 을 navigate 할 수 있습니다.

반응형

accordion menu Customizing 하기

2012. 12. 22. 19:19 | Posted by 솔웅


반응형
Customize accordion menus




이전 글에서 언급했던 CSS 를 이용해서 accordion menu 를 customizing 할 수 있습니다. title 과 content 두 부분 모두를 customizing 한 예제입니다.


Styling accordion menus


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

  

  <style type=text/css>

    .ui-collapsible-heading span.ui-btn-text {

      font-style : normal;

      color : red;

    }

    .ui-collapsible-heading-collapsed span.ui-btn-text{

      font-style : italic;

      color : black;

    }

    .ui-collapsible-content {

      background : black;

      color : white;

      text-align : center;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <div id=id1 data-role=collapsible>

      <h1>Menu 1 : Click to open / close</h1>

      <p> Paragraph 1.1 </p>

      <p> Paragraph 1.2 </p>

      <p> Paragraph 1.3 </p>

    </div>

    <div id=id2 data-role=collapsible>

      <h1>Menu 2 : Click to open / close</h1>

      <p> Paragraph 2.1 </p>

      <p> Paragraph 2.2 </p>

      <p> Paragraph 2.3 </p>

    </div>

  </div>

</div>


</body>

</html>



tistory560_01.html




반응형

accordion menu에서 이벤트 관리하기

2012. 12. 22. 05:47 | Posted by 솔웅


반응형
Manage events on accordion menus



accordion menu 를 좀 더 쉽게 관리하기 위해 jQuery mobile 은 bind () method로 다룰 수 있는 두 가지 새로운 이벤트를 만들었습니다.

  • The expand event warns that accordion menu was opened (it is already open)

  • The collapse event warns that accordion menu was closed (it is already closed).


이 두 이벤트들은 <div> elements 에 accordion menu를 정의하면( data-role="collapsible" attribute) 사용할 수 있습니다.


Use the expand and collapse events on the accordion menu


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <div id=id1 data-role=collapsible>

      <h1>Menu 1 : Click to open / close</h1>

      <p> Paragraph 1.1 </p>

      <p> Paragraph 1.2 </p>

      <p> Paragraph 1.3 </p>

    </div>

    <div id=id2 data-role=collapsible>

      <h1>Menu 2 : Click to open / close</h1>

      <p> Paragraph 2.1 </p>

      <p> Paragraph 2.2 </p>

      <p> Paragraph 2.3 </p>

    </div>

  </div>

</div>


</body>

</html>


<script>


$("#id1, #id2").bind ("collapsiblecreate", function (event)

{

  $(this).bind ("collapse", function (event)

  {

    alert ("Menu: closed");

  });

  $(this).bind ("expand", function (event)

  {

    alert ("Menu: open");

  });

});


</script>


tistory559_01.html


expand and collapse events 를 observation 하는 것은 jQuery Mobile 에 의해서 새로운 HTML 코드로 완전히 변환되고 난 후에 일어납니다.


Ajax에 의해 서버로 call 하는 동안에 accordion menu 를 생성해 보겠습니다.


Use the expand and collapse events in accordion menus retrieved by Ajax


<!DOCTYPE html> 

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p>This is an accordion menu </p>

  </div>

</div>


</body>

</html>


<script>


$.ajax (

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

    $("#home div:jqmData(role=content)").append (response);

    

    $("#id1, #id2").collapsible ();


    $("#id1, #id2").bind ("collapse", function (event)

    {

      alert ("Menu: closed");

    });

    $("#id1, #id2").bind ("expand", function (event)

    {

      alert ("Menu: open");

    });

  }

}); 


</script>


action.php file


<?
$html = "";
$html .= "<div id=id1 data-role=collapsible>";
$html .=   "<h1>Menu 1 : Click to open / close </h1>";
$html .=   "<p> Paragraph 1.1 </p>";
$html .=   "<p> Paragraph 1.2 </p>";
$html .=   "<p> Paragraph 1.3 </p>";
$html .= "</div>";
$html .= "<div id=id2 data-role=collapsible>";
$html .=   "<h1>Menu 2 : Click to open / close </h1>";
$html .=   "<p> Paragraph 2.1 </p>";
$html .=   "<p> Paragraph 2.2 </p>";
$html .=   "<p> Paragraph 2.3 </p>";
$html .= "</div>";
$html .= "</div>";
echo utf8_encode ($html);
?>



action26.php

tistory559_02.html



반응형


반응형

이번 대선 결과가 그렇게 난 후 한국 뉴스는 안 접하고 있습니다.

가슴이 쓰리거든요. ;;


제가 사는 로드 아일랜드 지역 인터넷 신문을 보다 보니까 수요일에 있은 미스 유니버스 대회에서 여기 출신이 1등에 뽑혔네요.


정말 정말 반가운 소식입니다. ^^


이번에 holiday season 에 집에 돌아온다고 하는데...

혹시 한번 만나볼수 있을까요?????? ;;



Breaking News
Miss Universe Olivia Culpo coming home to Cranston for the holidays


December 20, 2012 3:50 pm
By Jenna Pelletier



The morning after winning the Miss Universe pageant, Olivia Culpo answers questions during an interview Thursday in Las Vegas.

미스 유니버스 대회에서 1등한 다음날 아침, Olivia Culpo 가 라스베가스에서 목요일 인터뷰에 응하고 있다.



Thrilled and exhausted after her Wednesday night Miss Universe win, Olivia Culpo said she's looking forward to coming home to Cranston for the holidays and "just relaxing."

"I'm excited to see how happy Rhode Island is and it's going to be great to go back," Culpo, 20, said in an interview.


수요일 미스 유니버스에서 우승하고 난 후 그녀는 감격해 있었고 또 지쳐 있었다. Olivia Culpo 는 크리스마스와 연말 시즌을 보내러 Cranston 의 집으로 가는 날을 고대하고 있다고 말했다. 그리고 "그냥 쉴거예요. 저는 로드 아일랜드가 얼마나 행복한지 보고 싶어요 아마 금의환향이 될 거예요." 라고 그녀는 인터뷰에서 말했다.




Echoing comments she made in June after winning the Miss USA crown, Culpo said she thinks it was her ability to "just be myself" that earned her the title.

"It goes to show that you can do anything you want to do as long as you work hard and have the right attitude," she added.

No formal homecoming events are planned at this time.


참고로 그녀는 6월에 Miss USA 왕관을 차지했었다. Culpo는 그냥 솔직한 나 자신을 보여줬던게 이런 좋을 결과를 가져올수 있었다고 말했다.

"열심히 일하고 올바르게 행동하면 당신이 원하는 것은 무엇이든지 할 수 있다는 것을 보여줄거예요." 라고 그녀는 덧 붙였다.

아직까지 공식적인 그녀에 대한 homecoming event는 없다.


IN THE PAPER

Friday: Read more from staff writer Jenna Pelletier's interview with Olivia Culpo, in The Providence Journal.

금요일 The Providence Journal 종이 뉴스에서 Jenna Pelletier 가 진행한 Olivia Culpo 에 대한 더 많은 인터뷰 내용을 보세요.



반응형

PHP와 XSL 로 XML 변환하기

2012. 12. 21. 05:31 | Posted by 솔웅


반응형
How to parse XML with PHP5




Feeds 는 content 의 stream 으로 사람들이 웹사이트를 통해 정보의 조각들을 공유하기 위해 만든 것입니다. PHP5의 simpleXML 함수는 이 feed를 웹페이지에서 사용하기 편하도록 interpret 하는 방법을 아주 간단하게 구현할 수 있도록 도와 줍니다.


저는 최근 저희의 라디오 방송국 playlist 에서 제공하는 노래에 대한 live feed를 display 하는 widget 과 관련해서 작업을 했었습니다. radio 방송국에서 운영하는 시스템에서는 XML을 제공하는데요 이 자료들은 데이터베이스에서 나옵니다. 프로그램은 그 데이터를 feed로 만들어서 제공합니다.






서로 다른 서버끼리 데이터를 공유하기 위해 XML 을 사용하는 것은 일반적인 방법입니다. playlist 를 generate 하는 시스템은 proprietary 입니다. XML은 어떤 데이터가 공유될 수 있도록 하는 easy format 을 제공합니다.


XML 은 뭘까요?


XML 은 eXtensible Markup Language 의 줄임말로 site들 사이에서 공유하기 위해 데이터를 structure 하는 방법입니다. RSS (Real Simple Syndication) 와 Podcasts 같은 기술들도 XML 의 특별한 형태입니다. XML이 좋은 점은 여러분이 필요로 하는것을 여러분이 원하는 대로 표현할 수 있다는 겁니다.



XML은 쉽게 생성할 수 있습니다. 왜냐하면 HTML 이랑 아주 비슷하거든요. HTML 과 다른 점은 여러분만의 tag 를 따로 만들 수 있다는 겁니다. 예를 들어 여러분의 라디오 방송국에서 틀어줄 노래들의 list 에 대한 feed 를 put 한다고 가정합시다. 그러기 위해서 할 일은 당지 artist 이름, 노래 제목, 노래가 방송된 시긴 등을 encode 합니다. 이와 관련된 tag들을 만들 겁니다. <title> <artist> 그리고 이것들은 <song> tag 가 감쌀 겁니다. 또 우리는 각 노래가 방송된 시간을 표시할 건데요. 날짜와 시간이 여기에 들어갈 겁니다.

여러분은 이것을 아래 처럼 encode 할 수 있을 겁니다.


<songs>
    <song dateplayed="2011-07-24 19:40:26">
        <title>I left my heart on Europa</title>
        <artist>Ship of Nomads</artist>
    </song>
    <song dateplayed="2011-07-24 19:27:42">
        <title>Oh Ganymede</title>
        <artist>Beefachanga</artist>
    </song>
    <song dateplayed="2011-07-24 19:23:50">
        <title>Kallichore</title>
        <artist>Jewitt K. Sheppard</artist>
    </song>
</songs>



여기서 XML 데이터를 만들 때 지켜야 될 몇가지 규칙이 있습니다. 만약 XHTML 에 대해 잘 아신다면 쉽게 이해가 가실겁니다. 한번 볼까요?

   *  XML is case sensitive so <Title>` is not the same as <title>.
   *  All XML elements must have closing tags.
   *  XML requires a root element (the <songs> tag above serves as our root element)
   *  Attributes must be quoted
   *  Special characters (like & (&amp;) and < (&lt;) and > (&gt;) signs) must be encoded.

XML 은 HTML 보다 좀 더 strict 합니다. 하지만 정말 만들고 다루기가 쉽습니다.




Introducing simpleXML



simpleXML 을 사용해서 XML을 아주 쉽게 읽어서 그 내용에 접근할 수 있습니다.

위에 있는 XML 을 songs.xml 로 저장했다고 칩시다. 같은 폴더에 php 파일을 만들 겁니다.

이 전체 XML 을 아래 코드를 사용해서 읽을 겁니다.


<?php
    $mysongs = simplexml_load_file('songs.xml');
?>



이렇게 하면 다 읽은 겁니다. 저 xml 파일이 웹상의 어딘가에 있어도 그 URL 만 가지고 이렇게 읽을 수 있습니다. xml 파일이 여러분 서버에 있을 필요도 없는 거죠.

이제 우리는 이 파일의 내용을 담은 object (객체)를 가지게 됐습니다.

이 song 객체는 $mysongs 라는 변수에 담겨져 있습니다. 만약에 첫번째 artist 의 이름을 출력하고 싶다면 이렇게 하시면 됩니다.


<?php
    $mysongs = simplexml_load_file('songs.xml');
    echo $mysongs->song[0]->artist;
?>






이 객체의 일부분으로 XML tag 들이 매핑돼 있다는 걸 기억하세요. 그래서 그 name 을 통해 어느 element 이든 우리가 얻어 낼 수 있는 겁니다. 그리고 PHP 에서는 배열이 0번부터 시작한다는 것도 기억하시구요. 그래서 배열의 0번째 title을 위와 같이 출력한 겁니다.

자 이제 3번째 노래 제목을 출력해 볼까요?


<?php
    $mysongs = simplexml_load_file('songs.xml');
    echo $mysongs->song[2]->title;
?>





Working with Attributes



date 들을 얻으려면 그 attribute들에 어떻게 접근해야 되는지 알아야 됩니다. 이 notation은 tag 랑은 약간 다릅니다. 하지만 사용하는 건 똑 같이 쉽습니다.
바로 아래 처럼 사용하시면 됩니다.

<?php
    $mysongs = simplexml_load_file('songs.xml');
    echo $mysongs->song[1]['dateplayed'];
?>




Making a list of songs


So now that we’ve got the basics of accessing elements, let’s write the code to make a complete list of our songs parsed by interpreting our XML file.

이제 우리는 element들에 어떻게 접근하는지 그 기본을 알게 됐습니다.

이제 이 XML 파일을 interpret 함으로서 전체 노래를 parse 하도록 하겠습니다.


<?php
    $mysongs = simplexml_load_file('songs.xml');
    echo "<ul id="songlist">n";
    foreach ($mysongs as $songinfo):
        $title=$songinfo->title;
        $artist=$songinfo->artist;
        $date=$songinfo['dateplayed'];
        echo "<li><div class="title">",$title,"</div><div class="artist">by ",$artist,"</div><time>",$date,"</time></li>n";
    endforeach;
    echo "</ul>";
?>



각각의 노래들에 대해 접근하기 위해 우리는 foreach statement 를 사용했습니다. 그리고 그 정보를 간단한 HTML list 로 parsing 했습니다. 여러분은 이것을 일반적인 HTML 문서로 사용하시거나 아니면 노래 리스트를 출력하는 widget 으로 사용하실 수 있습니다.





Parsing a Flickr feed from a set


온라인에는 여러분이 parse 할만한 수 많은 XML feed 들이 있습니다. 예를 들어 Flickr 로부터 feed를 받을 수 있죠. 만약 여러분이 Flickr 를 update 하면 이 widget 은 자동적으로 이것을 여러분 웹싸이트에 display 할 겁니다.

예제로 사용하기 위해 약간의 고양이 사진들을 준비했습니다.
이 feed 에 대한 XML 을 얻으려면 Flickr 내의 웹 페이지로 가야 합니다. 그리고 화면 왼쪽 아래에 있는 XML icon 을 보세요.





우선 이 XML 의 구조를 알기 위해 이것을 분석해야 합니다. 이 feed 링크에서 오른쪽 마우스를 클릭해서 여러분의 하드 드라이브에 저장해 보세요. 그리고 이것을 photoset.xml 이라고 이름 짓고 브라우저로 열어 보세요.







저는 Safari 로 이 XML 파일을 열었습니다. 이 구조를 한번 살펴 보죠. 각각의 photo 들은 <entry> tag 안에 있죠? 그 안에 두개의 <link> tag 가 있네요. 첫번째 것은 Flickr 상의 이미지 링크이고 두번째 것은 이 이미지의 medium size 버전에 대한 링크가 있습니다.



위 예제를 살짝 바꿔보죠. 그리고 이 이미지들에 대한 thumbnail 을 표시하기 위해 두번째 link 를 살짝 조절하겠습니다. 이 작업을 하기 전에 Flickr 로 돌아가서 그 XML 파일의 경로를 얻으세요. 그리고 아래와 같이 코딩해 보세요.



<?php
    $mypix = simplexml_load_file('http://api.flickr.com/services/feeds/photoset.gne?set=72157627229375826&nsid=73845487@N00&lang=en-us');
    foreach ($mypix->entry as $pixinfo):
        $title=$pixinfo->title;
        $link=$pixinfo->link['href'];
        $image=str_replace("_b.jpg","_s.jpg",$pixinfo->link[1]['href']);
        echo "<a href="",$link,""><img src="",$image,"" alt="",$title,"" /></a>n";
    endforeach;
?>



<img> tag 의 alt text 로 <title> tag 를 사용할 겁니다. 그리고 anchor tag 의 href attribute 로 첫번째 <link> tag 를 사용할 거구요. 두번째 link 는 약간의 트릭을 사용했습니다. 두번째 링크의 href attribute ($pixinfo->link[1]['href']) 를 얻기 위해 array notation 을 사용할 수 있습니다. 그렇게 해서 우리가 필요한 큰 이미지를 얻게 될 겁니다. 이미지 이름을 바꾸기 위해서 str_replace 함수를 사용할 겁니다. 그러면 아래와 같은 thumbnail 을 얻게 될 겁니다.



Conclusion


simpleXML 은 정말 쉬워서 이것을 이용하면  Flickr 예제 같은 복잡한 feed를 parse 하는 것이 재밌을 겁니다. <entry> tag 안의 <link> tag 의 두번째 instance를 얻는데 아무런 문제가 없었던 점을 기억하세요. 이 작업은 이전 버전의 PHP 에서는 구현하기가 매우 어려웠을 겁니다. simpleXML 에는 다른 많은 기능들이 있습니다. 더 자세한 내용은 PHP manual을 보세요.
객체지향적인 접근에 관심이 있다면 PHP5 가 제공하는 SimpleXMLElement class도 도움이 될 겁니다.







반응형