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

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

使用第一行文本值java獲取第二行xml

使用第一行文本值java獲取第二行xml

九州編程 2022-07-20 20:24:06
  public void loadSettings() {        try {            File inputFile = new File("data.xml");            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();            Document doc = dBuilder.parse(inputFile);            doc.getDocumentElement().normalize();            NodeList nList = doc.getElementsByTagName("Setting");            for (int temp = 0; temp < nList.getLength(); temp++) {                Node nNode = nList.item(temp);                if (nNode.getNodeType() == Node.ELEMENT_NODE) {                    Element eElement = (Element) nList.item(temp);                    NodeList  VariableName = eElement.getElementsByTagName("VariableName");                    NodeList  VariableValue = eElement.getElementsByTagName("VariableValue");                    System.out.println(VariableName.item(0).getTextContent());                    if (VariableName.item(0).hasChildNodes()) {                    }//                    txtBookmarkUrl.setText(bookMarkUrl);                }            }        } catch (Exception e) {            e.printStackTrace();        }    }我想創(chuàng)建一個(gè)函數(shù),在設(shè)置元素中獲取 xml 的第二部分。我希望該函數(shù)返回一個(gè)結(jié)果,以便在 swing GUI 啟動(dòng)時(shí)將其分配給文本字段默認(rèn)值。該函數(shù)應(yīng)該使用“isDecaptcher”變量名并返回“0”變量值。<Bookmark>  <Setting>    <VariableName>isDeathbycaptcha</VariableName>    <VariableValue>0</VariableValue>  </Setting>  <Setting>    <VariableName>isDecaptcher</VariableName>    <VariableValue>0</VariableValue>  </Setting>  <Setting>    <VariableName>isExpertdecoders</VariableName>    <VariableValue>0</VariableValue>  </Setting>  <Setting>    <VariableName>ManualCaptcha</VariableName>    <VariableValue>1</VariableValue>  </Setting></Bookmark>
查看完整描述

2 回答

?
慕斯709654

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

public void loadSettings(String variableName) {


    try {

        File inputFile = new File("data.xml");

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

        Document doc = dBuilder.parse(inputFile);

        doc.getDocumentElement().normalize();

        NodeList nList = doc.getElementsByTagName("Setting");

        for (int temp = 0; temp < nList.getLength(); temp++) {

            Node nNode = nList.item(temp);

            if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                Element eElement = (Element) nList.item(temp);

                NodeList VariableName = eElement.getElementsByTagName("VariableName");

                NodeList VariableValue = eElement.getElementsByTagName("VariableValue");

                if (VariableName.item(0).getTextContent().equalsIgnoreCase(variableName)) {


                    String txtBookmarkUrlValue = VariableValue.item(0).getLastChild().getTextContent();

                    System.out.println(txtBookmarkUrlValue);

                    txtBookmarkUrl.setText(txtBookmarkUrlValue);

                }

            }

        }

    } catch (Exception e) {

        e.printStackTrace();

    }

}

這行得通,但是如果您有更可靠的答案,您可以分享。


查看完整回答
反對(duì) 回復(fù) 2022-07-20
?
慕桂英3389331

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

首先創(chuàng)建一個(gè)代表您的設(shè)置的對(duì)象。案例是在整個(gè)應(yīng)用程序中重用它的值。我假設(shè)您一開(kāi)始只會(huì)使用一次,并且設(shè)置不會(huì)改變。單例模式適合那里。


final class Settings{


    private static volatile Settings instance = null;


    private boolean _isDeathByCaptcha;

    private boolean _manualCaptcha;


    ...

    //getters & setters

    public boolean isDeathByCaptcha(){

         return _isDeathByCaptcha;

    }


    public void setIsDeathByCaptcha(boolean isDeathByCaptcha){

         this._isDeathByCaptcha = isDeathByCaptcha;

    }


    private Settings(){}


    public static Settings getInstance(){

        if(instance == null){

            synchronized (Settings.class) {

                if (instance == null) {

                    instance = new Settings();

                }

            }

        }

        return instance;        

    }

}

之后,您可以致電Settings.getInstance().isDeathByCaptcha();獲取您的價(jià)值。當(dāng)然你需要用 setter 更早地設(shè)置它。


查看完整回答
反對(duì) 回復(fù) 2022-07-20
  • 2 回答
  • 0 關(guān)注
  • 98 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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