How to modify XML data in Dom parser

落花浮王杯 提交于 2019-11-28 14:27:11

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

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

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

  • 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.


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 ...)


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

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

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.

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!

Kumar Vivek Mitra

1. The DOM Parser will parse the entire XML file to create the DOM object.

2. You will always need to be aware of the the type of output and the structure of xml returned when a request is fired on a web-service.

3. And its Not the XML structure of a reply which is returned from the Webservice that will be dynamic, but the child elements values and attributes can be Dynamic.

4. You will need to handle this dynamic behavior with try/catch block...

For further details on DOM PARSER, see this site...

http://tutorials.jenkov.com/java-xml/dom.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!