首页 > 代码库 > xml 杂记

xml 杂记

1.将字符串转换为xml文件

String str = "<TicketResult><type>1</type><orderNo>13052217251212120211XX030028</orderNo><names>李双胜,陈洋,晏永超</names><ticketNos>123-1232132112,123-1231231231,123-1232132132</ticketNos><pnr>HZ9XBP</pnr><oldPnr></oldPnr></TicketResult>";
			 StringReader sr = new StringReader(str); 
			 InputSource is = new InputSource(sr); 
			 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
			 builder = factory.newDocumentBuilder(); 
			 document = builder.parse(is);