Common commands for DOM parsing

Parse text

1.DocumentBuilderFactory.newInstance(); Factory mode. Returns a DocumentBuilder object

2.new DocumentBuilder();Create an object

3.documentbuilder.parse("dtd file path"); returns a doucument object

4.document.getElementsByTagName("node name"); returns the number of nodes;

Parse objects and elements

1.getChidNodes(); returns a LIst, including comments

2.list.item(intdex); returns a node object;

3.list.getLength(); returns the length of the list

4.node.getNodeTYPE(); returns a node type, if it is 1 to indicate the desired object, it can also be represented by NODE.ElEMENT_NODE

5. (Element) node; forcibly convert the node object into element;

6.element.getAttribute("att"); returns the node attribute;

7.element.getNodeName("");Text document;

8.element.TextContent();Text content;


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324693341&siteId=291194637