feuerjinn Geschrieben 2. Oktober 2015 Geschrieben 2. Oktober 2015 Heyho,Ich bau wie schon in dem anderen Thread erwähnt jetzt mein Bash Skript in ein Python skript um. So gesehen kann Python vieles besonders einfacher. Sehr coole Sache auf jeden Fall.Ich habe schon verschiedene XML-Parsing Implementationen ausprobiert, komme aber nich auf einen guten nenner.(lxml, xml.etree.EllementTree, xml.etree.cElementTree, XPATH)Folgende XML-Struktur habe ich. Erstmal ist nur der urn:jboss:domain:datasources:2.0 interessant.<?xml version="1.0" ?> <server xmlns="urn:jboss:domain:2.1"> <extensions> </extensions> <profile> <subsystem xmlns="urn:biz.paluch.logging:logstash-gelf-subsystem:1.0"/> <subsystem xmlns="urn:jboss:domain:logging:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:batch:1.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:datasources:2.0"> <datasources> <datasource jndi-name="java:jboss/datasources/JNDI" pool-name="JNDI" enabled="true"> <connection-url>jdbc:oracle:thin:@//HOST</connection-url> <driver>ojdbc6</driver> <pool> <min-pool-size>50</min-pool-size> <max-pool-size>100</max-pool-size> </pool> <security> <user-name>USER</user-name> <password>PWD</password> </security> <validation> <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/> <validate-on-match>false</validate-on-match> <background-validation>true</background-validation> <background-validation-millis>10000</background-validation-millis> <exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter"/> </validation> </datasource> <datasource jndi-name="java:jboss/datasources/JNDI" pool-name="JNDI" enabled="true"> <connection-url>jdbc:oracle:thin:@//HOST</connection-url> <driver>ojdbc6</driver> <pool> <min-pool-size>50</min-pool-size> <max-pool-size>100</max-pool-size> </pool> <security> <user-name>USER</user-name> <password>USER</password> </security> <validation> <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/> <validate-on-match>false</validate-on-match> <background-validation>true</background-validation> <background-validation-millis>10000</background-validation-millis> <exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter"/> </validation> </datasource> <datasource jndi-name="java:jboss/datasources/JNDI" pool-name="JNDI" enabled="true"> <connection-url>jdbc:oracle:thin:@//HOST</connection-url> <driver>ojdbc6</driver> <pool> <min-pool-size>50</min-pool-size> <max-pool-size>100</max-pool-size> </pool> <security> <user-name>USER</user-name> <password>USER</password> </security> <validation> <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/> <validate-on-match>false</validate-on-match> <background-validation>true</background-validation> <background-validation-millis>10000</background-validation-millis> <exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter"/> </validation> </datasource> <datasource jndi-name="java:jboss/datasources/InstanceConfiguration" pool-name="InstanceConfiguration" enabled="true" use-ccm="true"> <connection-url>jdbc:h2:/path/h2config/InstanceConfiguration;ACCESS_MODE_DATA=r;FILE_LOCK=NO</connection-url> <driver>h2</driver> <security> <user-name>USER</user-name> <password>USER</password> </security> </datasource> <drivers> <driver name="h2" module="com.h2database.h2"> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> <driver name="ojdbc6" module="oracle.ojdbc"> <xa-datasource-class>oracle.ojdbc.xa.client.OracleXADataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem> <subsystem xmlns="urn:jboss:domain:deployment-scanner:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:ee:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:ejb3:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:io:1.1"> </subsystem> <subsystem xmlns="urn:jboss:domain:infinispan:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:jacorb:1.3"> </subsystem> <subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/> <subsystem xmlns="urn:jboss:domain:jca:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:jdr:1.0"/> <subsystem xmlns="urn:jboss:domain:jmx:1.3"> </subsystem> <subsystem xmlns="urn:jboss:domain:jpa:1.1"> </subsystem> <subsystem xmlns="urn:jboss:domain:jsf:1.0"/> <subsystem xmlns="urn:jboss:domain:jsr77:1.0"/> <subsystem xmlns="urn:jboss:domain:mail:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:messaging:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:naming:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:pojo:1.0"/> <subsystem xmlns="urn:jboss:domain:remoting:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:resource-adapters:2.0"/> <subsystem xmlns="urn:jboss:domain:sar:1.0"/> <subsystem xmlns="urn:jboss:domain:security:1.2"> </subsystem> <subsystem xmlns="urn:jboss:domain:transactions:2.0"> </subsystem> <subsystem xmlns="urn:jboss:domain:undertow:1.1"> </subsystem> <subsystem xmlns="urn:jboss:domain:webservices:1.2"> </subsystem> <subsystem xmlns="urn:jboss:domain:weld:2.0"/> </profile> <interfaces> <interface name="management"> <inet-address value="${jboss.bind.address.management:127.0.0.1}"/> </interface> <interface name="public"> <inet-address value="${jboss.bind.address:127.0.0.1}"/> </interface> <interface name="unsecure"> <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/> </interface> </interfaces> <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}"> <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/> <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/> <socket-binding name="ajp" port="${jboss.ajp.port:8009}"/> <socket-binding name="http" port="${jboss.http.port:8080}"/> <socket-binding name="https" port="${jboss.https.port:8443}"/> <socket-binding name="jacorb" interface="unsecure" port="3528"/> <socket-binding name="jacorb-ssl" interface="unsecure" port="3529"/> <socket-binding name="messaging-group" port="0" multicast-address="${jboss.messaging.group.address:231.7.7.7}" multicast-port="${jboss.messaging.group.port:9876}"/> <socket-binding name="txn-recovery-environment" port="4712"/> <socket-binding name="txn-status-manager" port="4713"/> <outbound-socket-binding name="mail-smtp"> <remote-destination host="localhost" port="25"/> </outbound-socket-binding> <outbound-socket-binding name="remote-ejb"> <remote-destination host="localhost" port="${jboss.http.port:8080}"/> </outbound-socket-binding> </socket-binding-group> </server> Mein Code sähe so aus:In[3]: import xml.etree.cElementTree as xtree In[7]: xml = xtree.parse('standalone-full.xml') In[8]: xml Out[8]: <ElementTree at 0x482e588> In[9]: root = xml.getroot() In[10]: root Out[10]: <Element '{urn:jboss:domain:2.1}server' at 0x0000000004836030> In[11]: root.getchildren() Out[11]: [<Element '{urn:jboss:domain:2.1}extensions' at 0x0000000004836060>, <Element '{urn:jboss:domain:2.1}system-properties' at 0x0000000004836AE0>, <Element '{urn:jboss:domain:2.1}management' at 0x0000000004836B70>, <Element '{urn:jboss:domain:2.1}profile' at 0x000000000483CB40>, <Element '{urn:jboss:domain:2.1}interfaces' at 0x000000000490F8A0>, <Element '{urn:jboss:domain:2.1}socket-binding-group' at 0x000000000490FC30>] In[13]: for children in root.findall('{urn:jboss:domain:2.1}profile'): ... datasources = children.find('{urn:jboss:domain:datasources:2.0}datasources') ... print datasources ... NoneJemand ne Idee wie ich das anstellen kann?Danke. Zitieren
feuerjinn Geschrieben 13. Oktober 2015 Autor Geschrieben 13. Oktober 2015 Wurde jetzt mit einer RegEx gelöst. Ist nicht schön, aber bringt ein Ergebnis:import re In[133]: data = fo.readfile('standalone-full.xml') # liest den inhalt der datei ein In[134]: data Out[134]: '<?xml version="1.0" ?>\n\n<server xmlns="urn:jboss:domain:2.1">\n\n <extensions>\n In[135]: re.findall(r'.*:domain:datasources[\S\s]*?pool-name="JNDI"[\S\s]*?connection-url>.*@//(.*)<.*[\S\s]*?user-name>(.*)<.*\s*<password>(.*)<', data, re.M) Out[135]: [('HOST', 'USER', 'PWD')] Zitieren
Empfohlene Beiträge
Dein Kommentar
Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.