久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Dom 解析器中修改 XML 數(shù)據(jù)

How to modify XML data in Dom parser(如何在 Dom 解析器中修改 XML 數(shù)據(jù))
本文介紹了如何在 Dom 解析器中修改 XML 數(shù)據(jù)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我是 Java 和 XML DOM 解析器的新手.我有一個要求,比如讀取 xml 數(shù)據(jù)并將其存儲為列和行類型的通知.示例:sample.xml 文件

I am new working in Java and XML DOM parser. I had a requirement like read the xml data and store it inform of column and rows type. Example:sample.xml file

<staff>
        <firstname>Swetha</firstname>
        <lastname>EUnis</lastname>
        <nickname>Swetha</nickname>
        <salary>10000</salary>
    </staff>
    <staff>
        <firstname>John</firstname>
        <lastname>MAdiv</lastname>
        <nickname>Jo</nickname>
        <salary>200000</salary>
    </staff>

我需要讀取這個 XML 文件并以上述格式存儲:

i need to read this XML file and store it in the above format:

firstName,lastName,nickName,Salary
swetha,Eunis,swetha,10000
john,MAdiv,Jo,200000

Java 代碼:

NodeList nl= doc.getElementsByTagName("*");

        for(int i=0;i< nl.getLength();i++)
        {
            Element section = (Element) nl.item(i);

             Node title = section.getFirstChild();
              while (title != null && title.getNodeType() != Node.ELEMENT_NODE)
              {
                   title = title.getNextSibling();
                if (title != null)
              {
                String first=title.getFirstChild().getNodeValue().trim();
                    if(first!=null)
                    {
                        title = title.getNextSibling();
                    }
                System.out.print(first + ",");
               } }
              System.out.println("");
        }//for

我做了上面的代碼,但我無法找到以上述列和行格式獲取數(shù)據(jù)的方法.任何人都可以請幫我解決我的問題,我從過去的很多天里都在調查它

I did the above code, but i am not able to find the way to get the data in the above column and row format. Can any one please please kindly help me in solving my issue, i am looking into it from past many days

推薦答案

由于這看起來像家庭作業(yè),所以我會給你一些提示:

Since this looks like homework, I'm going to give you some hints:

  • 很可能你的講師給了你一些關于處理 XML DOM 的講義和/或示例.再讀一遍.

  • The chances are that your lecturer has given you some lecture notes and/or examples on processing an XML DOM. Read them all again.

getElementsByTagName 方法將元素名稱作為參數(shù)."*" 不是有效的元素名稱,因此調用不會返回任何內容.

The getElementsByTagName method takes an element name as a parameter. "*" is not a valid element name, so the call won't return anything.

您的代碼需要反映 XML 的結構.本例中的 XML 結構由 N 個 staff 元素組成,每個元素都包含名為 firstnamelastnamenicknamesalary.

Your code needs to mirror the structure of the XML. The XML structure in this case consists of N staff elements, each of which contains elements named firstname, lastname, nickname and salary.

您的講師也可能希望您使用類似 XSLT 或 XML 綁定機制的東西來簡化這一點.(或者也許這個 旨在成為 XMI 而不是 XML ......其中還有其他方法來處理這個......)

It is also possible that your lecturer expects you to use something like XSLT or an XML binding mechanism to simplify this. (Or maybe this was intended to be XMI rather than XML ... in which there are other ways to handle this ...)

我保留getElementsByTagName方法參數(shù)*",因為要動態(tài)讀取數(shù)據(jù).

I kept getElementsByTagName method parameter "*" because to read the data dynamically.

好吧,它不起作用!!DOM getElementsByTagName 方法不接受任何類型的模式.

Well, it doesn't work!! The DOM getElementsByTagName method does NOT accept a pattern of any kind.

如果你想讓你的代碼通用,你不能使用getElementsByTagName.您需要從頂部開始遍歷樹,從 DOM 的根節(jié)點開始.

If you want to make your code generic, you can't use getElementsByTagName. You will need to walk the tree from the top, starting with the DOM's root node.

能否請您提供示例數(shù)據(jù).

Can you please provide me with sample data.

沒有.你的講師不同意我給你復制代碼.但是,我要指出,網(wǎng)絡上有很多 XML DOM 教程,它們應該可以幫助您弄清楚您需要做什么.最好的事情是你自己做這項工作.這樣你會學到更多……這就是你作業(yè)的重點!

No. Your lecturer would not approve of me giving you code to copy from. However, I will point out that there are lots of XML DOM tutorials on the web which should help you figure out what you need to do. The best thing is for you to do the work yourself. You will learn more that way ... and that is the whole point of your homework!

這篇關于如何在 Dom 解析器中修改 XML 數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(fā)(Google 驅動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 黄色毛片在线看 | 日韩中文一区二区三区 | 亚洲aⅴ一区二区 | 9999视频| 成人免费黄色片 | 91视频进入 | 欧洲免费视频 | 中文字幕在线一区二区三区 | 日韩国产中文字幕 | 在线观看欧美一区 | 中文字幕一区二区三区乱码在线 | 91精品国产91久久综合桃花 | 91久久国产综合久久91精品网站 | 精品一区二区三区91 | 国产欧美一区二区三区在线看 | 啪视频在线 | 台湾佬久久 | 日韩免费高清视频 | 精品一区国产 | 免费在线观看h片 | 91传媒在线观看 | 国产免费播放视频 | www国产亚洲精品 | 国产片一区二区三区 | 精品国产一区二区三区性色av | 国产成人精品网站 | 免费艹逼视频 | 91精品国产乱码久久久久久久久 | 欧美一区二区三区免费在线观看 | 欧美日韩综合视频 | 亚洲一二三区精品 | 亚洲成人一区二区三区 | av中文字幕在线观看 | 国产日韩欧美二区 | 欧美精品一区二区三区蜜桃视频 | 91精品国产91久久久久久丝袜 | 亚洲福利视频网 | 精品久久久久一区二区国产 | 欧美一区二区三区大片 | 国产一区二区 | 国产网站久久 |