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

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

如何使用 Java 從 XML 文件中獲取屬性

如何使用 Java 從 XML 文件中獲取屬性

青春有我 2023-04-19 16:32:53
我為Oracle Access Manager開發(fā)了一個(gè)身份驗(yàn)證插件簡而言之,它包含:類以下XML我正在嘗試從XML文件中動態(tài)獲取<Value>an 的標(biāo)記 。<Attribute><Plugin type="Authentication">    <author>Phill</author>    <email>phill@example.com</email>    <creationDate>12:47:00, 2019-07-11</creationDate>    <description>Phill-Plugin</description>    <configuration>        <AttributeValuePair>            <Attribute type="string" length="60">GenerateUrl</Attribute>            <mandatory>true</mandatory>            <instanceOverride>false</instanceOverride>            <globalUIOverride>true</globalUIOverride>            <value>This is the value i'm trying to retrieve</value>        </AttributeValuePair>    </configuration></Plugin>類            try {                CredentialParam tem = context.getCredential().getParam("GenerateUrl");                String temp = (String) tem.getValue();                System.out.println("TEST: " + temp);                generateUrl = temp + "The User" + user;            } catch (Exception e) {                System.out.println("\n\n\n-------------------\n");                System.out.println("-      Input Is:         -\n");                System.out.println("-       "+e+"            -\n");                System.out.println("-------------------\n");                generateUrl = "A URL" + "The User" + user;            }重要的提示:該context對象是AuthenticationContext包含有關(guān)插件信息的實(shí)例根據(jù) Oracle 的文檔,這是某人檢索的確切方式Attribute,但我總是得到NullPointerException還有其他方法可以檢索嗎<Value>?
查看完整描述

2 回答

?
qq_遁去的一_1

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

我不得不嘗試另一種方法并正確解析XML


如果你可以在這里使用外部庫是如何:



    public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {

        File stocks = new File("PhillPlugin.xml");

            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

            Document doc = dBuilder.parse(stocks);

            doc.getDocumentElement().normalize();


            NodeList nodes = doc.getElementsByTagName("AttributeValuePair");


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

              Node node = nodes.item(i);

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

                Element element = (Element) node;

                if(i==0)

                 {

                 tempurlGen=getValue("value",element);

                   System.out.println("GenerateUrl: " + getValue("value", element));

                 }

                 else if (i==1)

                 {

                 tempurlVal=getValue("value",element);

                 System.out.println("ValidateUrl: " + getValue("value", element));

                 }


              }

            }

          }

          static String getValue(String tag, Element element) {

            NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();

            Node node = (Node) nodes.item(0);

            return node.getNodeValue();

          }


如果你不能javax在這里包含庫是如何解析XML使用流



    public void getXMLData() throws Exception {

        File stocks = new File("PhillPlugin.xml");

        BufferedInputStream in = new BufferedInputStream(new FileInputStream(stocks));

        StringBuilder sb = new StringBuilder();

        int cp;

        while ((cp = in.read()) != -1) {

            sb.append((char) cp);

            String t = sb.toString();

            if (t.contains("</AttributeValuePair>")) {

                String test = sb.toString();

                String test1p[] = test.split("<value>|</value>");

                tempurlGen = test1p[1];

                break;

            }

        }


        sb = new StringBuilder();

        while ((cp = in.read()) != -1) {


            sb.append((char) cp);

            String t = sb.toString();

            if (t.contains("</AttributeValuePair>")) {

                String test = sb.toString();

                String test1p[] = test.split("<value>|</value>");

                tempurlVal = test1p[1];

                break;

            }


        }

    }


確保你定義tempurlGen和tempurlVal



查看完整回答
反對 回復(fù) 2023-04-19
?
人到中年有點(diǎn)甜

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

嘗試這個(gè):


@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = {

    "author",

    "email",

    "creationDate",

    "description",

    "configuration"

})

@XmlRootElement(name = "Plugin")

public class Plugin {


    //Add getters and setters including ones for inner classes


    @XmlElement(required = true)

    private String author;

    @XmlElement(required = true)

    private String email;

    @XmlElement(required = true)

    private String creationDate;

    @XmlElement(required = true)

    private String description;

    @XmlElement(required = true)

    private Plugin.Configuration configuration;

    @XmlAttribute(name = "type")

    private String type;


    @XmlAccessorType(XmlAccessType.FIELD)

    @XmlType(name = "", propOrder = {

        "attributeValuePair"

    })

    public static class Configuration {


        @XmlElement(name = "AttributeValuePair", required = true)

        private Plugin.Configuration.AttributeValuePair attributeValuePair;


        @XmlAccessorType(XmlAccessType.FIELD)

        @XmlType(name = "", propOrder = {

            "attribute",

            "mandatory",

            "instanceOverride",

            "globalUIOverride",

            "value"

        })

        public static class AttributeValuePair {


            @XmlElement(name = "Attribute", required = true)

            private Plugin.Configuration.AttributeValuePair.Attribute attribute;

            @XmlElement(required = true)

            private String mandatory;

            @XmlElement(required = true)

            private String instanceOverride;

            @XmlElement(required = true)

            private String globalUIOverride;

            @XmlElement(required = true)

            private String value;


            @XmlAccessorType(XmlAccessType.FIELD)

            @XmlType(name = "", propOrder = {

                "value"

            })

            public static class Attribute {


                @XmlValue

                private String value;

                @XmlAttribute(name = "type")

                private String type;

                @XmlAttribute(name = "length")

                private Byte length;


            }


        }


    }


}

對于解組部分:


JAXBContext jaxbContext = JAXBContext.newInstance(Plugin.class);

Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

StringReader reader = new StringReader("xml string here");

Plugin plugin = (Plugin) unmarshaller.unmarshal(reader); 


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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