第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從 XML 中刪除所有出現(xiàn)的特定屬性

從 XML 中刪除所有出現(xiàn)的特定屬性

慕田峪7331174 2023-10-12 14:38:06
我有一個(gè) XML 文件,內(nèi)容如下<document>  <section>    <section SectionName="abstract">     <paragraph>    <word Endpoint="1" SciomeSRIE_Sentence.ExposureSentence="1">gutkha</word>    <word ExposureSentence="1">split_identifier ,</word>    <word ExposureSentence="1">and</word>    <word ExposureSentence="1">what</word>    <word ExposureSentence="1">role</word>    <word ExposureSentence="1">split_identifier ,</word>    <word ExposureSentence="1">if</word>    <word ExposureSentence="1">any</word>    <word ExposureSentence="1">split_identifier ,</word>    <word ExposureSentence="1">nicotine</word>    <word ExposureSentence="1">contributes</word>    <word ExposureSentence="1">to</word>    <word ExposureSentence="1">the</word>    <word ExposureSentence="1">effects</word>    <word ExposureSentence="1">split_identifier .</word>    <word EB_NLP_Tagger.Participant="3" AnimalGroupSentence="1" DoseGroupSentence="1" ExposureSentence="2">Adult</word>    <word EB_NLP_Tagger.Participant="3" Sex="1" AnimalGroupSentence="1" DoseGroupSentence="1" ExposureSentence="2">male</word>    <word EB_NLP_Tagger.Participant="3" Species="1" AnimalGroupSentence="1" DoseGroupSentence="1" ExposureSentence="2">mice</word>    <word AnimalGroupSentence="1" DoseGroupSentence="1" ExposureSentence="2">were</word>    <word AnimalGroupSentence="1" DoseGroupSentence="1" ExposureSentence="2">treated</word>    <word AnimalGroupSentence="1" DoseGroupSentence="1" ExposureSentence="2">daily</word>    <word AnimalGroupSentence="1" DoseGroupSentence="1" ExposureSentence="2">for</word>
查看完整描述

2 回答

?
慕標(biāo)5832272

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊

XPath 使這變得簡單:


public static void main(String... args)

        throws Exception

{

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

    Document doc = dBuilder.parse(new ByteArrayInputStream(xml.getBytes()));


    XPathFactory xPathfactory = XPathFactory.newInstance();

    XPath xpath = xPathfactory.newXPath();


    // Find word elements with ExposureSentence attribute

    XPathExpression query = xpath.compile("//word[@ExposureSentence]");

    NodeList words = (NodeList) query.evaluate(doc, XPathConstants.NODESET);

    for (int i = 0; i < words.getLength(); i++) {

        // Remove the attribute

        ((Element) words.item(i)).removeAttribute("ExposureSentence");

    }


    // Handle ComponentName

    query = xpath.compile("//ComponentName");

    NodeList componentNames = (NodeList) query.evaluate(doc, XPathConstants.NODESET);

    for (int i = 0; i < componentNames.getLength(); i++) {

        String content = componentNames.item(i).getTextContent();

        componentNames.item(i).setTextContent(

            Arrays.stream(content.split(","))

                .map(String::trim)

                .filter(s -> !s.equals("ExposureSentence"))

                .collect(Collectors.joining(", ")));

    }


    // Omitted: Save the XML

}


查看完整回答
反對 回復(fù) 2023-10-12
?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊

我認(rèn)為最簡單的解決方案是ExposureSentence="1"使用簡單的正則表達(dá)式替換所有出現(xiàn)的情況。將所有 xml 內(nèi)容讀取為 String,并替換所有不需要 XML 解析和替換的特定單詞出現(xiàn)位置。

在 XML 解析的情況下,您需要解析、操作邏輯,并且必須重建 XML 信息集。


查看完整回答
反對 回復(fù) 2023-10-12
  • 2 回答
  • 0 關(guān)注
  • 139 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號