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

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

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

問題描述

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

我需要讀取這個(gè) XML 文件并以上述格式存儲(chǔ):

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ù)的方法.任何人都可以請(qǐng)幫我解決我的問題,我從過去的很多天里都在調(diào)查它

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è),所以我會(huì)給你一些提示:

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

  • 很可能你的講師給了你一些關(guān)于處理 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ù)."*" 不是有效的元素名稱,因此調(diào)用不會(huì)返回任何內(nèi)容.

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

您的代碼需要反映 XML 的結(jié)構(gòu).本例中的 XML 結(jié)構(gòu)由 N 個(gè) staff 元素組成,每個(gè)元素都包含名為 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 綁定機(jī)制的東西來簡化這一點(diǎn).(或者也許這個(gè) 旨在成為 XMI 而不是 XML ......其中還有其他方法來處理這個(gè)......)

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ù)*",因?yàn)橐獎(jiǎng)討B(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é)點(diǎn)開始.

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.

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

Can you please provide me with sample data.

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

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!

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

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

相關(guān)文檔推薦

Upload progress listener not fired (Google drive API)(上傳進(jìn)度偵聽器未觸發(fā)(Google 驅(qū)動(dòng)器 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(谷歌驅(qū)動(dòng)api服務(wù)賬戶查看上傳文件到谷歌驅(qū)動(dòng)使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務(wù)帳號(hào)返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 亚洲九九精品 | 91在线精品视频 | 国产精品久久久久久吹潮 | 华丽的挑战在线观看 | 亚洲男女激情 | 国产男女视频 | 看毛片的网站 | 中文字幕专区 | 色综合久久久久 | 黄色日本片 | 亚洲第一色av| 亚洲精品三级 | 成人av免费看 | 中文字幕亚洲区一区二 | 高清av电影| 成人av鲁丝片一区二区小说 | 久久大| 欧洲成人免费视频 | 亚洲精品成人 | 中文字幕在线网 | 欧美黑人巨大videos精品 | 99久久久久国产精品免费 | 一级片在线免费看 | 免费在线观看一区二区 | 一区二区三区国产好 | 国产精品一区二区在线 | 免费中文字幕 | 一区二区三区观看视频 | 日韩三级电影一区二区 | 日韩精品在线观看一区二区 | 久久久久久久一区二区三区 | 欧美一二三 | 亚洲自拍偷拍欧美 | 国产一区二区免费 | 天天天操操操 | 亚洲欧美日韩国产综合 | 欧美精品二区 | 天天干免费视频 | 久久久久久久久久一区 | 91精品国产欧美一区二区成人 | 久久99精品久久 |