在oracle中元素形成一个xml

declare
  results CLOB;
  p xmlparser.Parser;
  document xmldom.DOMDocument;
  rootelement xmldom.DOMElement;
  stockRecord xmldom.DOMElement;
  fieldsSet stockmarket%rowtype;
  tempelement xmldom.DOMElement;
  textnode xmldom.DOMNode;
  tempnode xmldom.DOMNode;
  --type ref_cur is ref cursor return ref_cur;
  --user_cur ref_cur;
  --sqlstr varchar2;定义用户输入的sql语句
  --终极目标,使用动态游标实现(待解决问题 1、数组  2、获得游标的列数)
  stock_code char(6);
  stock_name varchar2(50);
  stock_shortname varchar2(30);
  cursor user_cur is
         select * from stockmarket; 
  begin
       document:=xmldom.newDOMDocument;--建立document文档对象
       rootelement:=xmldom.createElement(document,'Stocktable');--建立该对象的根元素
       open user_cur;
       loop
           fetch user_cur into fieldsSet;
           exit when user_cur%notfound;
           stock_code:=fieldsSet.stockcode;
           stock_name:=fieldsSet.stockname;
           stock_shortname:=fieldsSet.stockshortname;
          
           stockRecord:=xmldom.createElement(document,'Stock');--Stock记录
          
           tempelement:=xmldom.createElement(document,'StockCode');
           textnode:=xmldom.makeNode(xmldom.createTextNode(document,fieldsSet.stockcode));
           tempnode:=xmldom.appendChild(xmldom.makeNode(tempelement),textnode);
           tempnode:=xmldom.appendChild(xmldom.makeNode(stockRecord),xmldom.makeNode(tempelement));
          
           tempelement:=xmldom.createElement(document,'StockName');
           textnode:=xmldom.makeNode(xmldom.createTextNode(document,fieldsSet.stockname));
           tempnode:=xmldom.appendChild(xmldom.makeNode(tempelement),textnode);
           tempnode:=xmldom.appendChild(xmldom.makeNode(stockRecord),xmldom.makeNode(tempelement));
          
           tempelement:=xmldom.createElement(document,'StockShortName');
           textnode:=xmldom.makeNode(xmldom.createTextNode(document,fieldsSet.stockshortname));
           tempnode:=xmldom.appendChild(xmldom.makeNode(tempelement),textnode);
           tempnode:=xmldom.appendChild(xmldom.makeNode(stockRecord),xmldom.makeNode(tempelement));
          
           tempnode:=xmldom.appendChild(xmldom.makeNode(rootelement),xmldom.makeNode(stockRecord));
           /**
           textnode:=xmldom.makeNode(xmldom.createTextNode(document,fieldsSet.stockname));
           xmldom.appendChild(tempelement,textnode);
          
           textnode:=xmldom.makeNode(xmldom.createTextNode(document,fieldsSet.stockshortname));
           xmldom.appendChild(tempelement,textnode);
          
           xmldom.appendChild(stockRecord,tempelement);
           xmldom.appendChild(rootelement,stockRecord);
           */
          
       end loop;
       --将根元素添加到Document对象
       tempnode:=xmldom.appendChild(xmldom.makeNode(document),xmldom.makenode(rootelement));
       xmldom.writeToFile(document,'c:/111.xml');

  end;

你可能感兴趣的:(oracle,sql,C++,c,xml)