Home
Wir über uns
Produkte, Leistungen
Jobs
Kontakt
Download
Webimpressum
 

hello.xml

<?xml version="1.0" encoding="UTF-8"?>
<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="hello.xsd">
<Names>
<Name>Frank</Name>
<Name>Klaus</Name>
<Name>Piece_of_crap</Name>
</Names>
</xml>

hello.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Name" type="xs:string" />
<xs:element name="Names">
<xs:complexType>
<xs:sequence>
<xs:element ref="Name" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="xml">
<xs:complexType>
<xs:sequence>
<xs:element ref="Names"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

MAIN

import java.io.FileInputStream;
import java.io.File;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Node;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Locale;

public class MAIN {
/**
* The classic HelloWorld in Java with maximum flexibility.
* SCHÖNE NEUE WELT
* YOU DON'T need THIS
* @param args not used
*/
public static void main(String[] args) {
try {
Properties properties = new Properties();
ResourceBundle resourceBundle = ResourceBundle.getBundle("LocalizedHello", Locale.US);
//ResourceBundle.getBundle("LocalizedHello", Locale.getDefault());

Node node = null;
CharacterData characterText = null;
StringBuffer stringBuffer = new StringBuffer(100);
DOMParser parser = new DOMParser();
// Turn on W3C Schema processing
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);

String defaultPropertyFile = System.getProperty("PropertyFile");
if (defaultPropertyFile == null) {
defaultPropertyFile = "HelloWorld.properties";
}
properties.load(new FileInputStream(new File(defaultPropertyFile)));
parser.parse(new InputSource(properties.getProperty("HelloWorldXMLFile")));
Document doc = parser.getDocument();

NodeList titles = doc.getElementsByTagName("Name");

for (int i = 0; i < titles.getLength(); i++) {
stringBuffer.append(resourceBundle.getString("Hello.MAIN"));
stringBuffer.append(" ");
node = titles.item(i);
characterText = (CharacterData) node.getFirstChild();
stringBuffer.append(characterText.getData());
stringBuffer.append("\n");
}
System.out.println(stringBuffer.toString());
} catch (Throwable
e) {
System.out.println("Fehler beim Parsen oder sonst wo (who cares)!");
e.printStackTrace(System.out);
}
}
}

HelloWorld.properties

HelloWolrdXMLFile=hello.xml

LocalizedHello_de_DE.properties

Hello.MAIN=Hallo

LocalizedHello_en_US.properties

Hello.MAIN=Hello

   
Top