How to modify XML data in Dom parser

后端 未结 2 694
清歌不尽
清歌不尽 2020-12-12 03:04

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

         


        
相关标签:
2条回答
  • 2020-12-12 03:20

    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

    0 讨论(0)
  • 2020-12-12 03:21

    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!

    0 讨论(0)
提交回复
热议问题