读取xml java,Java读取xml数据

  • Post author:
  • Post category:java


b013d4d6e75b918c0e5a31a82ad36e71.png

xml中的代码

书名1

100

书名2

300

java中的代码

import java.io.File;

import java.io.IOException;

import javax.lang.model.element.Element;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.soap.Node;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

import org.xml.sax.SAXException;

public class ReadXml {

public static void main(String[] args) {

try {

//java读取xml的方法。DOM方式

DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();

DocumentBuilder builder=factory.newDoc