2016-06-21 4 views
0

는 내가 XML 데이터를 가지고 그리고 난 일반 테이블 형식으로 변환하려고 :데이터

city   survey 

    Pune   abc 

    mumbai   xyz 

    ahmednagar 

    delhi 
: 나는 테이블의 형태로 데이터를 가져 오기 위해 노력하고

<html> 
    <head> 
    <title>report</title> 
    <model> 
     <instance> 
     <uploaded_form_dc8u7x id="reportform"> 
      <formhub> 
      <uuid/> 
      </formhub> 
      <household_number/> 
      <Survey_Name/> 
      <photo/> 
      <city/> 
      <date/> 
      <survey/> 
      <start/> 
      <end/> 
      <meta> 
      <instanceID/> 
      </meta> 
     </uploaded_form_dc8u7x> 
     </instance> 
     <bind constraint=" /uploaded_form_dc8u7x/household_number &gt;= 2" nodeset="/uploaded_form_dc8u7x/household_number" required="true()" type="int"/> 
     <bind nodeset="/uploaded_form_dc8u7x/Survey_Name" relevant=" /uploaded_form_dc8u7x/household_number &gt; 02" required="true()" type="string"/> 
     <bind nodeset="/uploaded_form_dc8u7x/photo" required="true()" type="binary"/> 
     <bind nodeset="/uploaded_form_dc8u7x/city" required="true()" type="select"/> 
     <bind nodeset="/uploaded_form_dc8u7x/date" required="true()" type="dateTime"/> 
     <bind nodeset="/uploaded_form_dc8u7x/survey" required="true()" type="select1"/> 
     <bind preload="timestamp" preloadParams="start" nodeset="/uploaded_form_dc8u7x/start" type="dateTime"/> 
     <bind preload="timestamp" preloadParams="end" nodeset="/uploaded_form_dc8u7x/end" type="dateTime"/> 
     <bind calculate="concat('uuid:', uuid())" nodeset="/uploaded_form_dc8u7x/meta/instanceID" readonly="true()" type="string"/> 
     <bind calculate="'05ef936fe45e41d1bc08474399d64191'" nodeset="/uploaded_form_dc8u7x/formhub/uuid" type="string"/> 
    </model> 
    </head> 
    <body> 
    <input ref="/uploaded_form_dc8u7x/household_number"> 
     <label>Household Number</label> 
    </input> 
    <input ref="/uploaded_form_dc8u7x/Survey_Name"> 
     <label>Survey Name</label> 
    </input> 
    <upload mediatype="image/*" ref="/uploaded_form_dc8u7x/photo"> 
     <label>photo</label> 
    </upload> 
    <select ref="/uploaded_form_dc8u7x/city"> 
     <label>city</label> 
     <item> 
     <label>pune</label> 
     <value>pune01</value> 
     </item> 
     <item> 
     <label>mumbai</label> 
     <value>mumbai02</value> 
     </item> 
     <item> 
     <label>ahmednagar</label> 
     <value>ahmednagar03</value> 
     </item> 
     <item> 
     <label>delhi</label> 
     <value>delhi04</value> 
     </item> 
    </select> 
    <input ref="/uploaded_form_dc8u7x/date"> 
     <label>date</label> 
    </input> 
    <select1 ref="/uploaded_form_dc8u7x/survey"> 
     <label>survey</label> 
     <item> 
     <label>xyz</label> 
     <value>xyz1</value> 
     </item> 
     <item> 
     <label>abc</label> 
     <value>abc1</value> 
     </item> 
    </select1> 
    </body> 
</html> 

누구나 나를 도울 수 있습니까?

이것을 달성하기위한 선택 쿼리는 무엇이되어야합니까?

postgresSQL을 통해 테이블 ​​형식으로 데이터를 선택하려고합니다. 나는 "도시"와 "조사"를 데이터가 언급 된 별도의 컬럼으로 원한다. "{푸네, 뭄바이,

"{abc 방송, XYZ} "

SELECT xpath('/html/body/input/label/text()', xml_content) as house_number from logger_xform; 

그것은 나에게 대신 별도의 열 한 행의 결과를주고있다 :

나는 다음과 같은 쿼리를 시도했다 아마드 나가르, 델리}는 "

답변

1

이 시도 :

  with table1 as (select $$<html> 
       <head> 
       <title>report</title> 
       <model> 
        <instance> 
        <uploaded_form_dc8u7x id="reportform"> 
         <formhub> 
         <uuid/> 
         </formhub> 
         <household_number/> 
         <Survey_Name/> 
         <photo/> 
         <city/> 
         <date/> 
         <survey/> 
         <start/> 
         <end/> 
         <meta> 
         <instanceID/> 
         </meta> 
        </uploaded_form_dc8u7x> 
        </instance> 
        <bind constraint=" /uploaded_form_dc8u7x/household_number &gt;= 2" nodeset="/uploaded_form_dc8u7x/household_number" required="true()" type="int"/> 
        <bind nodeset="/uploaded_form_dc8u7x/Survey_Name" relevant=" /uploaded_form_dc8u7x/household_number &gt; 02" required="true()" type="string"/> 
        <bind nodeset="/uploaded_form_dc8u7x/photo" required="true()" type="binary"/> 
        <bind nodeset="/uploaded_form_dc8u7x/city" required="true()" type="select"/> 
        <bind nodeset="/uploaded_form_dc8u7x/date" required="true()" type="dateTime"/> 
        <bind nodeset="/uploaded_form_dc8u7x/survey" required="true()" type="select1"/> 
        <bind preload="timestamp" preloadParams="start" nodeset="/uploaded_form_dc8u7x/start" type="dateTime"/> 
        <bind preload="timestamp" preloadParams="end" nodeset="/uploaded_form_dc8u7x/end" type="dateTime"/> 
        <bind calculate="concat('uuid:', uuid())" nodeset="/uploaded_form_dc8u7x/meta/instanceID" readonly="true()" type="string"/> 
        <bind calculate="'05ef936fe45e41d1bc08474399d64191'" nodeset="/uploaded_form_dc8u7x/formhub/uuid" type="string"/> 
       </model> 
       </head> 
       <body> 
       <input ref="/uploaded_form_dc8u7x/household_number"> 
        <label>Household Number</label> 
       </input> 
       <input ref="/uploaded_form_dc8u7x/Survey_Name"> 
        <label>Survey Name</label> 
       </input> 
       <upload mediatype="image/*" ref="/uploaded_form_dc8u7x/photo"> 
        <label>photo</label> 
       </upload> 
       <select ref="/uploaded_form_dc8u7x/city"> 
        <label>city</label> 
        <item> 
        <label>pune</label> 
        <value>pune01</value> 
        </item> 
        <item> 
        <label>mumbai</label> 
        <value>mumbai02</value> 
        </item> 
        <item> 
        <label>ahmednagar</label> 
        <value>ahmednagar03</value> 
        </item> 
        <item> 
        <label>delhi</label> 
        <value>delhi04</value> 
        </item> 
       </select> 
       <input ref="/uploaded_form_dc8u7x/date"> 
        <label>date</label> 
       </input> 
       <select1 ref="/uploaded_form_dc8u7x/survey"> 
        <label>survey</label> 
        <item> 
        <label>xyz</label> 
        <value>xyz1</value> 
        </item> 
        <item> 
        <label>abc</label> 
        <value>abc1</value> 
        </item> 
       </select1> 
       </body> 
      </html>$$::xml xml_content) 

      select city,surveys[i] survey from (
      select generate_subscripts(citys,1) i,unnest(citys) city,surveys from (
       select xpath($$//*[@ref='/uploaded_form_dc8u7x/city']/item/label/text()$$,xml_content) citys,xpath($$//*[@ref='/uploaded_form_dc8u7x/survey']/item/label/text()$$,xml_content) surveys from table1 
      ) a 
      ) b 
+0

레미, 모자를 사람이 당신에게 떨어져 ... !! 당신이 이것에 대해 정말 잘 알고있는 것 같습니다 ... 우리는이 주제에 대해 연락 할 것입니다 ... –