How to convert String to DOM Document object in java?

前端 未结 4 1777
抹茶落季
抹茶落季 2020-12-15 18:28

I have a case like getting an XML and convert the XML elements to document object and getting the element values and attributes which i have been created already

Her

4条回答
  •  臣服心动
    2020-12-15 19:01

         public static void main(String[] args) {
        final String xmlStr = "\n"+
                                "Pankaj25\n"+
                                "DeveloperMale";
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
            DocumentBuilder builder;  
            try 
            {  
                builder = factory.newDocumentBuilder();  
                Document doc = builder.parse( new InputSource( new StringReader( xmlStr )) ); 
    
            } catch (Exception e) {  
                e.printStackTrace();  
            } 
      }
    

提交回复
热议问题