How to convert string to xml file in java -
<?xml version="1.0" encoding="utf-8"?><soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"><soap:body><loginresponse xmlns="http://tempuri.org/questiphonewebservice/questiphonewebservice"><loginresult><return_value><error result= '-1' desc = 'the password entered system not valid. please check password , try again.'/></return_value></loginresult></loginresponse></soap:body></soap:envelope>
hi getting value webservices. want convert above string xml can tell how convert string xml file in java
<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <soap:body> <loginresponse xmlns="http://tempuri.org/questiphonewebservice/questiphonewebservice"> <loginresult> <root xmlns:sql="urn:schemas-microsoft-com:xml-sql"><login_details user_id="testpub2" company_id="1" user_name=" aaa" system_user_id="6976" user_email_id="hcltestpub2@hsdlgsdmnk0098.com" token_string="a93805f1f1c340f5a8155fdd9b77e595" disclaimer_agreed="1" user_enabled="1" user_company_enabled="1" user_type="2" login_expiry_days="999" token_creation_date="2010-10-01t16:04:26" mobile_enabled="1" user_company_mobile_enabled="1"/><company_details client_type_id="8"/><user_settings><quest_group id="14293" name="world" assign_num="14"/><index_provider id="14251" name="quest (default)"/><stock_identifier id="57" name="ticker"/></user_settings><permissions><quest_functions><function name="charting" id="501" access="1"/><function name="modeller" id="512" access="1"/><function name="momentum" id="513" access="1"/><function name="portfolio" id="516" access="1"/><function name="search" id="518" access="1"/><function name="sensitivity" id="521" access="1"/><function name="statistics" id="524" access="1"/><function name="strategy" id="525" access="1"/><function name="summary" id="526" access="1"/><function name="triangle" id="528" access="1"/><function name="valuation" id="529" access="1"/><function name="commentary" id="530" access="1"/><function name="citn" id="534" access="1"/><function name="batch report" id="553" access="1"/><function name="modellerws" id="557" access="1"/><function name="sector analysis" id="562" access="1"/></quest_functions><admin_functions><function name="administrator" id="531" access="0"/><function name="author" id="532" access="1"/><function name="publisher" id="533" access="0"/><function name="editor" id="539" access="0"/></admin_functions></permissions></root> 10-04 14:30:08.696: debug/login result is(439): </loginresult></loginresponse></soap:body></soap:envelope>
the child node coming user_id="testpub2" have convert xnode , value how covert xml node? , take value using saxparser. can take value directly?
the below code converts string xml document. once have document, can navigate nodes or can write file etc.
import java.io.*; import javax.xml.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; public class util { public static document stringtodom(string xmlsource) throws saxexception, parserconfigurationexception, ioexception { documentbuilderfactory factory = documentbuilderfactory.newinstance(); documentbuilder builder = factory.newdocumentbuilder(); return builder.parse(new inputsource(new stringreader(xmlsource))); } }
Comments
Post a Comment