기상청의 xml 를 가공할려고 합니다. 도와주세요.

impactbar의 이미지

myroot님의 도움으로 기상청에서 제공하는 xml 파일 위치를 알게 되었습니다.

그래서 그것을 가공하기 위해서 xsl을 만들어 보았습니다.

weather.html에서 합쳐서 브라우저에 뿌려 줄려고 하는데

화면에는 안나오는 군요.

1.weather.html 파일에서 자바스크립트안에
xml.load("http://www.kma.go.kr/weather/xml/current.xml")
처럼 쓸 수 있는지요?

2.weather.xsl 파일에서
<tr>
<td><xsl:value-of select="local"/></td>
<td><xsl:value-of select="local/@ta"/></td>
</tr>
가 문법에 맞는 지요.

소스는 아래와 같습니다.
좋은 하루 되십시오.

weather.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
        <head>
                <title>WEATHER</title>
        </head>
        <body>
                <table border="1">
                        <tr>
                                <th>CITY</th>
                                <th>TEMP</th>
                        </tr>
                        <xsl:for-each select="current/weather/local">
                        <tr>
                                <td><xsl:value-of select="local"/></td>
                                <td><xsl:value-of select="local/@ta"/></td>
                        </tr>
                        </xsl:for-each>
                </table>
        </body>
</html>
</xsl:template>
</xsl:stylesheet>

weather.html

<html>
        <body>
                <script language="javascript">
                        // XML 문서 열기
                        var xml = new ActiveXObject("Microsoft.XMLDOM")
                        xml.async = false
                        xml.load("http://www.kma.go.kr/weather/xml/current.xml")
                        // XML 문서 열기
                        var xsl = new ActiveXObject("Microsoft.XMLDOM")
                        xsl.async = false
                        xsl.load("weather.xsl")
                        // 변형시키기
                        document.write(xml.transformNode(xsl))
                </script>
        </body>
</html>
kwon37xi의 이미지

자바 스크립트는 모르겠구요.. XSL은 다음이 맞을껍니다.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
   <xsl:template match="/">
      <html>
         <head>
            <title>WEATHER</title>
         </head>
         <body>
            <table border="1">
               <tr>
                  <th>CITY</th>
                  <th>TEMP</th>
               </tr>
               <xsl:for-each select="//local">
                  <tr>
                     <td>
                        <xsl:value-of select="."/>
                     </td>
                     <td>
                        <xsl:value-of select="./@ta"/>
                     </td>
                  </tr>
               </xsl:for-each>
            </table>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>
서지훈의 이미지

xml도 정말 사용ㅇ나한지 오래 된것 같은데...
이걸 이용하시는 분들도 이제 좀 늘어 날려나...^^

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

impactbar의 이미지

kwon37xi님 우선 답변 감사드리고요.

흠. 그런데 안보이는군요.

어디가 문제인지 모르겠습니다.

기상청 xml 소스에 문제가 있는건 아닌지.. ^^;

에구...xml 핸드북이라도 한권 사야겠군요. ^^

즐거운 하루 되세요.

kwon37xi의 이미지

impactbar wrote:
kwon37xi님 우선 답변 감사드리고요.

흠. 그런데 안보이는군요.

어디가 문제인지 모르겠습니다.

기상청 xml 소스에 문제가 있는건 아닌지.. ^^;

에구...xml 핸드북이라도 한권 사야겠군요. ^^

즐거운 하루 되세요.

XSL은 맞습니다.
XSLT 프로세서로 확인해봤습니다. JavaScript 오류가 뜨는거 같은데 확인해보시기 바랍니다.

impactbar의 이미지

네 감사합니다.

자바스크립트에서 url을 인식 못할리가 없는데 꿈쩍도 않네요.

다른 파일들로 예제로 하니까 되던 스크립트(너무간단하지만^^)라

혹시나 xml파일에 문제가 있지 않나 생각 중입니다.

좀 더 공부해 보겠습니다.

좋은 하루 되십시오.

bluemoon의 이미지

검색중에 보게되네요. 좀 지난 글이지만 관심있는 쪽이라 몇자적습니다.

이 문제는 자바스크립트의 (JScript라고 해야 정확하겠지요..)

progID = "MSXML2.DOMDocument.3.0";

try
{
    var xdoc = new ActiveXObject( /* progID */ );
    ...
    xml.load( /* url */ );
    ...
}
catch(e)
{
    alert( (e.number & 0xffff) + ':' + e.description );
}

예외처리를 통해 오류의 발생지를 짐작하실수 있으리라봅니다.
그리고 자바스크립트안에서 오류가 없다면 XSL문서보다 XPath구문에
문제가 있을 여지가 있습니다.
XML이 well-formed 문서라는 조건하에..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.