xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "tarundsk" <tarun...@datainfosys.net>
Subject Re: Manipulating a Xml Document.??
Date Tue, 30 Jan 2001 15:34:47 GMT
yes you can definitely do that thru SAX there are some methods like 
document.createElement() document.createNode() etc....
just look at The API's 

----- Original Message -----
From: "pankaj malhan" <pankajmalhan@hotmail.com>
Date: Monday, January 29, 2001 11:48 pm
Subject: Manipulating a  Xml Document.??

> <html><DIV>
> <P>
> hi 
> i'm new to XML.
> i want to maipulate a XML document (ADD attribute or
> delete or add a new element into existing XML document)
> i'm able to to all this by using DOm (I was using Ibm's parser)
> now i want to manifulate the XML document using 
> SAX2.0  .Can i do that ???.
> i'm able to parse and read the XML document by using 
> ContentHandler 
> Interface but i dont know how to manipulate the XML document.
> I'm using Xalan for Transformations of XML to HTML and WML.
> Is that i have to use Xerces???
> i have also dowmloaded JDOM API.How to Procced??....??</P>
> <P>Thx.</P>
> <P>Pankaj Malhan</P>
> <P>here is a sample code to manipulate a XML Document and the XML 
> document. </P>
> <P>
> import java.sql.*;
> import java.util.*;
> import java.io.*;</P>
> <P>import com.ibm.xml.parser.*;
> import org.w3c.dom.DOMException;
> import org.w3c.dom.*;   
> public class malhan1 
> {
> .....
>  ....
>    ......
>   Parser p1=new Parser("mama");
>    ByteArrayInputStream bais=new 
> ByteArrayInputStream(prvxmlstring.getBytes());    TXDocument doc = 
> null;    doc=p1.readStream(bais);
>    ....
>      ....
>      ...</P>
> <P>
> if(doc!=null)
>    {
>        String root = doc.getRootName();
>        System.out.println("Root name  "+root);
>            if(root!=null)
>              {
>         if(root.equalsIgnoreCase("SALESMAN_5"))
>    {
>             for(Node 
> Child=doc.getDocumentElement().getFirstChild();Child!
=null;Child=Child.getNextSibling())           {
>        if(Child instanceof Element)    
>                                     {
>     String name=Child.getNodeName();
>      System.out.println(name); </P>
> <P>     if(Child.getNodeName().equals("OPPORTUNITYS"))
>     {
>      
>      
> //item.appendChild(doc.createTextNode("OPPORTUNITY_ID=\"100\" 
NAME=\"xyz\" DESCRIPTION=\"PANKAJ MALHAN\"  DEPARTMENT=\"abc\" 
CONTACT_ID=\"3\" OPENING_DATE=\"12/12/2000\"  CLOSING_DATE=\"12/31/2000
\" REVENUE=\"1000\" PROBABILITY=\"10\" COMPETITORS=\"abc,xyz\""));
>      //item.appendChild(doc.createTextNode("NAME"));
>      
>      Element item=doc.createElement("OPPORTUNITY");
>      item.setAttribute("ID","4"); 
>                 item.setAttribute("NAME","malhan"); 
>      item.setAttribute("CID","2"); 
>       
>       Element item2=doc.createElement("DESCRIPTION");      
>      item2.appendChild(doc.createTextNode("good boy"));
>      item.appendChild(item2);
> 
>      item2=doc.createElement("DEPARTMENT");
>        item2.appendChild(doc.createTextNode("sss"));
>      item.appendChild(item2);
>      
>      item2=doc.createElement("CLOSING_DATE");
>        item2.appendChild(doc.createTextNode("23-dec-1977"));
>      item.appendChild(item2); 
>      
>      item2=doc.createElement("REVENUE");
>        item2.appendChild(doc.createTextNode("23889389"));
>      item.appendChild(item2);</P>
> <P>      item2=doc.createElement("PROBABILITY");
>        item2.appendChild(doc.createTextNode("23889389"));
>      item.appendChild(item2);</P>
> <P>      item2=doc.createElement("COMPETITORS");
>        item2.appendChild(doc.createTextNode("abc, xyz,wdj"));
>      item.appendChild(item2);
>  
>      Child.appendChild(item);
>     }</P>
> <P>            }
>   
>   
>    }  
>   FileOutputStream fo=new FileOutputStream("personal_details_5.xml");
>   ((TXDocument)doc).setVersion("1.0");
>   ((TXDocument)doc).printWithFormat(new PrintWriter(fo)); 
>   fo.close();   </P>
> <P>   }  
>    }
> </P>
> <P>-------------------------XML File----------------</P>
> <P><?xml version="1.0"?&gt;
> <SALESMAN_4&gt;
>  <SALESDET NAME="pankaj" TITLE="consultant" ACCOUNT_ID="1" 
> PHONE="5447737" ACCOUNT_NAME="ost" FAX="98439" ADDRESS="orgok" 
> EMAIL="pankajmalhan@yahoo.com" CITY="noida" TERRITORY="noida" 
> STATE="delhi" ZIP="110063" COUNTRY_ID="97" WEBSITE="pankaj.com" 
> CURRENCY_ID="9"&gt; 
>   </SALESDET&gt;
>  <OPPORTUNITYS&gt;
>    <OPPORTUNITY&gt;
> <OPPORTUNITY_ID="100" NAME="xyz" DESCRIPTION="PANKAJ MALHAN"  
> DEPARTMENT="abc" CONTACT_ID="3" OPENING_DATE="12/12/2000"  
> CLOSING_DATE="12/31/2000" REVENUE="1000" PROBABILITY="10" 
> COMPETITORS="abc,xyz"/&gt; </OPPORTUNITY&gt; 
> </OPPORTUNITYS&gt;
> </SALESMAN_4&gt;</P>
> <P>         ------------------------------</P>
> <P> </P></DIV><br clear=all><hr>Get Your Private, Free
E-mail from 
> MSN Hotmail at http://www.hotmail.com.
> </p></html>
> 
> -------------------------------------------------------------------
> --
> In case of troubles, e-mail:     webmaster@xml.apache.org
> To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org
> 
> 


Mime
View raw message