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

如何在 Dom 解析器中修改 XML 數據

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

問題描述

我是 Java 和 XML DOM 解析器的新手.我有一個要求,比如讀取 xml 數據并將其存儲為列和行類型的通知.示例: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

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

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

推薦答案

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

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 方法將元素名稱作為參數."*" 不是有效的元素名稱,因此調用不會返回任何內容.

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方法參數*",因為要動態讀取數據.

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 的根節點開始.

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.

能否請您提供示例數據.

Can you please provide me with sample data.

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

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 數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(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 示例中缺少)
主站蜘蛛池模板: 91国内在线观看 | 久久久人成影片一区二区三区 | 中文字幕免费视频 | 91在线看视频 | 成人亚洲一区 | 亚洲天堂一区二区 | 久久久91精品国产一区二区精品 | 欧美日韩视频在线 | 一区二区久久 | 国产精品久久久久久久久动漫 | 毛片日韩 | 日韩成人在线电影 | 久久亚洲国产精品日日av夜夜 | 久久久久久国产精品免费免费 | 做a网站| 精品亚洲第一 | 麻豆国产一区二区三区四区 | 777777777亚洲妇女 | 亚洲精品欧美一区二区三区 | 宅女噜噜66国产精品观看免费 | 国产一在线 | 精品国产一区二区三区久久影院 | 国产精品久久久久久模特 | 精品日韩一区 | 爱爱视频日本 | 亚洲国产精品一区二区第一页 | 亚洲一区二区中文字幕在线观看 | 中文区中文字幕免费看 | 日韩免费网站 | 羞羞的视频免费观看 | 九九久久久 | 欧美小视频在线观看 | 在线视频a | 日韩视频在线播放 | 欧美一区二区三区大片 | 精品在线免费观看视频 | 在线免费观看成人 | 欧美99 | av片网| 一级欧美一级日韩片免费观看 | 婷婷五月色综合香五月 |