![](/img/trans.png)
[英]parsing the xml to get the root element and then add a tag dynamically under the root tag
[英]parse the xml to find the root tag and then append the tags under the root tag
我的web目錄中有一個xml文件。 目前它看起來像:
<?xml version="1.0" encoding="UTF-8"?>
<Blobs>
</Blobs>
我想在標簽Blob下動態添加標簽blobkey 。 如果已添加標記,則下次應添加新標記。 我該怎么做呢 ? 首先,我需要解析xml文件,找到根元素,然后在作為根標記的Blobs標簽下添加一個名為blobkey的新標記。
這是我為此寫的一些代碼,但它不符合我的要求。請提出建議。
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
Element blobKey_E = document.createElement("BlobKey");
blobKey_E.appendChild( document.createTextNode( blobKey ) );
// Save the xml file after this
document.getDocumentElement().appendChild(blobKey_E)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.