[XML & Java] XML Schema, XML Dokument, XPath

amarte

Cadet 2nd Year
Registriert
Jan. 2005
Beiträge
19
Hallo!

Ich will mittels dom4j und XPath Einträge in meiner config.xml Datei extrahieren bzw. manipulieren.

XML Schema der config:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema"
		targetNamespace="http://wex.deri.at"
		xmlns:wex="http://wex.deri.at"
		xmlns:xs="http://www.w3.org/2001/XMLSchema" 
		elementFormDefault="qualified" 
		attributeFormDefault="unqualified">
	<xs:element name="config" type="wex:configType"/>
	<xs:complexType name="configType">
		<xs:sequence>
			<xs:element name="property" type="wex:propertyType" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="propertyType" mixed="true">
		<xs:simpleContent>
			<xs:extension base="xs:string">
				<xs:attribute name="name" type="wex:nameType" use="required"/>
				<xs:attribute name="value" type="wex:valueType" use="required"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>
	<xs:simpleType name="nameType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="sax.parser"/>
			<xs:enumeration value="dom.parser"/>
			<xs:enumeration value="sax.factory"/>
			<xs:enumeration value="dom.factory"/>
			<xs:enumeration value="dom.namespace.aware"/>
			<xs:enumeration value="dom.validating"/>
			<xs:enumeration value="dom.expand.entity.reference"/>
			<xs:enumeration value="dom.ignore.whitespace"/>
			<xs:enumeration value="dom.ignore.comments"/>
			<xs:enumeration value="dom.coalescing"/>
			<xs:enumeration value="log4j.config.file"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="valueType">
		<xs:restriction base="xs:string"/>
	</xs:simpleType>
</xs:schema>

Die config Datei:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://wex.deri.at"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://wex.deri.at schema.xsd">		
	<property name="dom.factory" value="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
	<property name="log4j.config.file" value="log4j.xml"/>
</config>

Beides, die config und die Schema Datei sind gültig. Wenn ich jetzt aber ein XPath auf das Dokument anwende, wie "//property[@name="dom.factory"]/@value" bekomm ich null zurückgeliefert. Mir leuchtet das Ganze nicht wirklich ein ...

Danke schon mal im Voraus
 
Zurück
Oben