簡體   English   中英

解析xml以查找根標記,然后在根標記下附加標記

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM