> Hello World !!!

     

@syaku

XPath 표현식을 이용한 XML 노드 검색 : selectSienleNode

XPath 표현식을 이용하여 XML 데이터 검색이 유용한 selectSingleNode 를 크로스브라우징하게 제공되는 함수 입니다. 기존 방식과 다르게 해당 노드의 text(value)를 리턴합니다.

 

XPath 표현식

/message/code[@id='title']/content 는?
/루트 message 노드 /자식 code 노드 [@ id속성의 값은 title] / 자식 content 노드

 

XML Source : test.xml

<?xml version="1.0" encoding="EUC-KR" ?>
<message>
  <code id="url">
    <content>http://syaku.springnote.com</content>
    <action>document.location.reload();</action>
  </code>
  <code id="title">
    <content>샤쿠님의 노트</content>
    <action>document.location.reload();</action>
  </code>
</message>

Example Source

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">
  <head>
    <title>테스트</title>
    <script type="text/javascript" src="./action.js"></script>
  </head>
  <body>
    <div>
      <h1>selectSingleNode</h1>
      <script type="text/javascript">
        //<![CDATA[
        // xSingleNodeValue("xml 파일 경로","찾을 노드")
          document.write(xSingleNodeValue("/test.xml","/message/code[@id='title']/content"));
        //]]>
      </script>
    </div>
  </body>
</html>

written by Seok Kyun. Choi. 최석균.
http://www.cyworld.com/syaku
http://syaku.tistory.com