| |

VerySource

 Forgot password?
 Register
Search
View: 766|Reply: 2

What's not understood in DOM parsing?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-17 15:40:01
| Show all posts |Read mode
<! DOCTYPE db-config SYSTEM "db-config.dtd">
<db-config>
<db-info id = "oracle">
<db-driver> oracle.jdbc.driver.OracleDriver </ db-driver>
<db-url> jdbc: oracle: thin: @ 192.168.1.78: 1521: ORDBA </ db-url>
<db-userName> scott </ db-userName>
<db-userPassword> tiger </ db-userPassword>
</ db-info>
<db-info id = "mysql">
<db-driver> com.mysql.jdbc.Driver </ db-driver>
<db-url> jdbc: mysql: // localhost: 3306 / jive? useUnicode = true&amp; characterEncoding = UTF-8 </ db-url>
<db-userName> root </ db-userName>
<db-userPassword />
</ db-info>
</ db-config>

I used the DOM to parse the xml document shown above, but there was a rather depressed place
I use
Element root = doc.getDocumentElement ();
Get the root element, next I use
NodeList nodeList = root.getElementsByTagName ("db-info");
To get its "db-info" child nodes,
It stands to reason that I continue to get its
NodeList nodeChileList = lement.getElementsByTagName ("db-driver");
But why use it when getting the "db-driver" element:
nodeChileList.item (0) .getFirstChild (). getNodeValue () method?
Instead of using the nodeChileList.item (0) .getNodeValue () method directly?
The getFirstChild () method is literally understood to get its first child node ???
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-22 08:45:02
| Show all posts
The same question
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-22 09:00:01
| Show all posts
Because dom regards the content of the element as a Node
nodeChileList.item(0) gets an element node
nodeChileList.item(0).getFirstChild(). Get the content node of the element
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list