如何读写如下XML文件,用XMLDocument. ( 积分: 50 )

  • 主题发起人 主题发起人 ifeng
  • 开始时间 开始时间
I

ifeng

Unregistered / Unconfirmed
GUEST, unregistred user!
XML文件如下:

有两个ResourceParams项,读第二个。

<?xml version='1.0' encoding='utf-8'?>
<Server>
<Listener className=&quot;org.apache.catalina.mbeans.ServerLifecycleListener&quot;/>
<Listener className=&quot;org.apache.catalina.mbeans.GlobalResourcesLifecycleListener&quot;/>
<GlobalNamingResources>
<Environment name=&quot;simpleValue&quot; type=&quot;java.lang.Integer&quot; value=&quot;30&quot;/>
<Resource auth=&quot;Container&quot; description=&quot;User database that can be updated and saved&quot; name=&quot;UserDatabase&quot; type=&quot;org.apache.catalina.UserDatabase&quot;/>
<Resource name=&quot;jdbc/ac990jcy&quot; type=&quot;javax.sql.DataSource&quot;/>
<ResourceParams name=&quot;UserDatabase&quot;>
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
<ResourceParams name=&quot;jdbc/ac990jcy&quot;>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=ac990jcy</value> //读写出此处的内容
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>maxActive</name>
<value>40</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>1000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>4</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
<Service name=&quot;Catalina&quot;>
<Connector URIEncoding=&quot;GB2312&quot; acceptCount=&quot;100&quot; connectionTimeout=&quot;20000&quot; disableUploadTimeout=&quot;true&quot; port=&quot;8080&quot; redirectPort=&quot;8443&quot; maxSpareThreads=&quot;75&quot; maxThreads=&quot;150&quot; minSpareThreads=&quot;25&quot;>
</Connector>
<Connector port=&quot;8009&quot; protocol=&quot;AJP/1.3&quot; protocolHandlerClassName=&quot;org.apache.jk.server.JkCoyoteHandler&quot; redirectPort=&quot;8443&quot;>
</Connector>
<Engine defaultHost=&quot;localhost&quot; name=&quot;Catalina&quot;>
<Host appBase=&quot;webapps&quot; name=&quot;localhost&quot; unpackWARs=&quot;false&quot;>
<Logger className=&quot;org.apache.catalina.logger.FileLogger&quot; prefix=&quot;localhost_log.&quot; suffix=&quot;.txt&quot; timestamp=&quot;true&quot;/>
</Host>
<Logger className=&quot;org.apache.catalina.logger.FileLogger&quot; prefix=&quot;catalina_log.&quot; suffix=&quot;.txt&quot; timestamp=&quot;true&quot;/>
<Realm className=&quot;org.apache.catalina.realm.UserDatabaseRealm&quot;/>
</Engine>
</Service>
</Server>
 
XML文件如下:

有两个ResourceParams项,读第二个。

<?xml version='1.0' encoding='utf-8'?>
<Server>
<Listener className=&quot;org.apache.catalina.mbeans.ServerLifecycleListener&quot;/>
<Listener className=&quot;org.apache.catalina.mbeans.GlobalResourcesLifecycleListener&quot;/>
<GlobalNamingResources>
<Environment name=&quot;simpleValue&quot; type=&quot;java.lang.Integer&quot; value=&quot;30&quot;/>
<Resource auth=&quot;Container&quot; description=&quot;User database that can be updated and saved&quot; name=&quot;UserDatabase&quot; type=&quot;org.apache.catalina.UserDatabase&quot;/>
<Resource name=&quot;jdbc/ac990jcy&quot; type=&quot;javax.sql.DataSource&quot;/>
<ResourceParams name=&quot;UserDatabase&quot;>
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
<ResourceParams name=&quot;jdbc/ac990jcy&quot;>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=ac990jcy</value> //读写出此处的内容
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>maxActive</name>
<value>40</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>1000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>4</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
<Service name=&quot;Catalina&quot;>
<Connector URIEncoding=&quot;GB2312&quot; acceptCount=&quot;100&quot; connectionTimeout=&quot;20000&quot; disableUploadTimeout=&quot;true&quot; port=&quot;8080&quot; redirectPort=&quot;8443&quot; maxSpareThreads=&quot;75&quot; maxThreads=&quot;150&quot; minSpareThreads=&quot;25&quot;>
</Connector>
<Connector port=&quot;8009&quot; protocol=&quot;AJP/1.3&quot; protocolHandlerClassName=&quot;org.apache.jk.server.JkCoyoteHandler&quot; redirectPort=&quot;8443&quot;>
</Connector>
<Engine defaultHost=&quot;localhost&quot; name=&quot;Catalina&quot;>
<Host appBase=&quot;webapps&quot; name=&quot;localhost&quot; unpackWARs=&quot;false&quot;>
<Logger className=&quot;org.apache.catalina.logger.FileLogger&quot; prefix=&quot;localhost_log.&quot; suffix=&quot;.txt&quot; timestamp=&quot;true&quot;/>
</Host>
<Logger className=&quot;org.apache.catalina.logger.FileLogger&quot; prefix=&quot;catalina_log.&quot; suffix=&quot;.txt&quot; timestamp=&quot;true&quot;/>
<Realm className=&quot;org.apache.catalina.realm.UserDatabaseRealm&quot;/>
</Engine>
</Service>
</Server>
 
后退
顶部