1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      使用java怎么將生成的xml轉(zhuǎn)換為字符串-創(chuàng)新互聯(lián)

      這篇文章將為大家詳細(xì)講解有關(guān)使用java怎么將生成的xml轉(zhuǎn)換為字符串,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

      10年積累的網(wǎng)站制作、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有烏拉特后免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。Java是什么

      Java是一門面向?qū)ο缶幊陶Z(yǔ)言,可以編寫桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序。

      如下所示:

      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.OutputKeys;
      import javax.xml.transform.Transformer;
      import javax.xml.transform.dom.DOMSource;
      import javax.xml.transform.stream.StreamResult;
       
      import org.apache.commons.io.output.ByteArrayOutputStream;
       
      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
       
      public class test {
      	
      	private String createXml() {
      		String xmlString = "";
       
      		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      		try {
      			DocumentBuilder builder = factory.newDocumentBuilder();
      			Document document = builder.newDocument();
      			document.setXmlStandalone(true);
       
      			Element itemInfo = document.createElement("ItemInfo");
      			document.appendChild(itemInfo);
       
      			Element itemStatistics = document.createElement("ItemStatistics");
      			itemStatistics.setTextContent("商品統(tǒng)計(jì)");
      			itemInfo.appendChild(itemStatistics);
       
      			Element items = document.createElement("Items");
      			itemInfo.appendChild(items);
      			// 此處可以循環(huán)添加
      			Element item = document.createElement("Item");
      			items.appendChild(item);
       
      			Element itemName = document.createElement("ItemName");
      			itemName.setTextContent("iPhone");
      			item.appendChild(itemName);
       
      			Element itemNum = document.createElement("ItemNum");
      			itemNum.setTextContent("3");
      			item.appendChild(itemNum);
       
      			Element itemValue = document.createElement("ItemValue");
      			itemValue.setTextContent("1000000");
      			item.appendChild(itemValue);
       
      			Element remark = document.createElement("Remark");
      			remark.setTextContent("配送");
      			itemInfo.appendChild(remark);
       
      			TransformerFactory transFactory = TransformerFactory.newInstance();
      			Transformer transformer = transFactory.newTransformer();
      			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      			DOMSource domSource = new DOMSource(document);
       
      			// xml transform String
      			ByteArrayOutputStream bos = new ByteArrayOutputStream();
      			transformer.transform(domSource, new StreamResult(bos));
      			xmlString = bos.toString();
      			System.out.println(xmlString);
      		} catch (Exception e) {
      			e.printStackTrace();
      		}
       
      		return xmlString;
      	}
      }

      結(jié)果:

      
      
      商品統(tǒng)計(jì)
      
      
      iPhone
      3
      1000000
      
      
      配送
      

      去掉頭文件

      的辦法暫時(shí)只能想到:

      xmlString.substring(38)

      關(guān)于使用java怎么將生成的xml轉(zhuǎn)換為字符串就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。


      當(dāng)前題目:使用java怎么將生成的xml轉(zhuǎn)換為字符串-創(chuàng)新互聯(lián)
      URL鏈接:http://ef60e0e.cn/article/dgchgs.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        永登县| 井冈山市| 韶山市| 通州区| 建宁县| 高雄县| 呼玛县| 花莲市| 巴林右旗| 瑞昌市| 民乐县| 建始县| 平江县| 馆陶县| 县级市| 白玉县| 邓州市| 西乌| 嘉定区| 汝南县| 梧州市| 安徽省| 桑日县| 郯城县| 乌苏市| 天柱县| 内乡县| 乐东| 黔西县| 阜平县| 宜城市| 巴塘县| 岳阳市| 兴和县| 桓仁| 镇坪县| 安塞县| 泽库县| 敦化市| 赤壁市| 延津县|