我自学的时候没有学过XML 只知道使用,后来知道的基础的知识,这才豁然开朗。
XML代码
<?xml version="1.0" encoding="UTF-8"?>
<employees id="1">
<employee>
<name>aa</name>
<sex>nv</sex>
</employee>
<employee id="2">
<name>bb</name>
<sex>nan</sex>
</employee>
</employees>
java里的代码
public class TestXML {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
InputStream xmlInputStream=TestXML.class.getResourceAsStream("/test.xml");
DocumentBuilderFactory builderFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=builderFactory.newDocumentBuilder();
Document document=builder.parse(xmlInputStream);
Element root=document.getDocumentElement();
System.out.println(root.getNodeName());
}
}
你不用明白他们的意思 ,你只需知道 再java类中能取到xml的值就行。
我们可以这么考虑,只要更改xml中值就可以改变java类中的值,因此配置文件的原理我们可以认为是这样 的---就是传值。