<转>plsql解析XML

文件:
<?xml   version="1.0"?>   
  <PEOPLE>   
  <PERSON   PERSONID="E01">   
  <NAME>Tony   Blair</NAME>   
  <ADDRESS>10   Downing   Street,   London,   UK</ADDRESS>   
  <TEL>(061)   98765</TEL><FAX>(061)   98768</FAX>   
  <EMAIL>[email protected]</EMAIL>   
  </PERSON>   
  <PERSON   PERSONID="E02">   
  <NAME>Bill   Clinton</NAME>   
  <ADDRESS>White   House,   USA</ADDRESS>   
  <TEL>(001)   6400   98765</TEL><FAX>(001)   6400   98769</FAX>   
  <EMAIL>[email protected]</EMAIL>   
  </PERSON>   
  <PERSON   PERSONID="E03">   
  <NAME>Tom   Cruise</NAME>   
  <ADDRESS>57   Jumbo   Street,   New   York,   USA</ADDRESS>   
  <TEL>(001)   4500   67859</TEL><FAX>(001)   4500   67895</FAX>   
  <EMAIL>[email protected]</EMAIL>   
  </PERSON>   
  <PERSON   PERSONID="E04">   
  <NAME>Linda   Goodman</NAME>   
  <ADDRESS>78   Crax   Lane,   London,   UK</ADDRESS>   
  <TEL>(061)   54   56789</TEL><FAX>(061)   54   56772</FAX>   
  <EMAIL>[email protected]</EMAIL>   
  </PERSON>   
  </PEOPLE>   

代码:
  declare   
      dir         varchar2(50);   
      infile   varchar2(20);   
      errlog   varchar2(20);   
      p             xmlparser.parser;   
      doc         xmldom.DOMDocument;   
      n1           xmldom.DOMNodeList;   
      len1       number(3);   
      n2           xmldom.DOMNodeList;   
      len2       number(3);   
      n3           xmldom.DOMNodeList;   
      len3       number(3);   
      v1           xmldom.DOMNode;   
      v2           xmldom.DOMNode;   
      v3           xmldom.DOMNode;   
      attn       xmldom.DOMNode;   
      strSQL   varchar2(200);   
      nnm         xmldom.DOMNamedNodeMap;   
  begin   
      dir         :=   'F:\xml';   
      infile   :=   'people.xml';   
      errlog   :=   'err.log';   
      p             :=   xmlparser.newParser;   
      xmlparser.setValidationMode(p,   false);   
      xmlparser.setErrorLog(p,   dir   ||   '\'   ||   errlog);   
      xmlparser.setBaseDir(p,   dir);   
      xmlparser.parse(p,   dir   ||   '\'   ||   infile);   
      doc   :=   xmlparser.getDocument(p);   
      xmlparser.freeParser(p);   
      n1           :=   xmldom.getElementsByTagName(doc,   'PEOPLE');   
      len1       :=   xmldom.getLength(n1);   
      for   i   in   0   ..   len1   -   1   loop   
          v1       :=   xmldom.item(n1,   i);   
          n2       :=   xmldom.getChildNodes(v1);   
          len2   :=   xmldom.getLength(n2);   
          for   j   in   0   ..   len2   -   1   loop   
                  strSQL   :=   'INSERT   INTO   POPLE   VALUES   (';   
              v2   :=   xmldom.item(n2,   j);   
              if   xmldom.getNodeName(v2)   =   'PERSON'   then   
                  nnm         :=   xmldom.getAttributes(v2);   
                  attn       :=   xmldom.item(nnm,   0);   
                  strSQL   :=   strSQL   ||   ''''   ||   to_char(xmldom.getNodeValue(attn))   ||   '''';   
              end   if;   
              n3       :=   xmldom.getChildNodes(v2);   
              len3   :=   xmldom.getLength(n3);   
              for   z   in   0   ..   len3   -   1   loop   
                  v3           :=   xmldom.item(n3,   z);   
                  strSQL   :=   strSQL   ||   ',   '''   ||   
                                      to_char(xmldom.getNodeValue(xmldom.getFirstChild(v3)))   ||   '''';   
              end   loop;   
              strSQL   :=   strSQL   ||   ')';   
              dbms_output.put_line(strSQL);   
              execute   immediate(strSQL);   
              commit;   
              strSQL:='';   
          end   loop;   
      end   loop;   
      --   释放文档对象   
      xmldom.freeDocument(doc);   
  end;   

你可能感兴趣的:(sql,xml,F#,J#)