Java/XML - (2006/05/11 (木) 15:48:55) の1つ前との変更点
追加された行は緑色になります。
削除された行は赤色になります。
**XMLプロセッサ実装の切替え
以下のシステムプロパティに対して使用したい実装のFactoryクラスを指定する。
javax.xml.parsers.SAXParserFactory
javax.xml.parsers.DocumentBuilderFactory
javax.xml.transform.TransformerFactory
例 : WeblogicのDOMパーサを指定する場合
System.setProperty(
"javax.xml.parsers.DocumentBuilderFactory",
"weblogic.xml.jaxp.RegistryDocumentBuilderFactory");
**XMLSchemaによるXML検証
DOMの場合です。
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
TestErrorHandler handler = new TestErrorHandler();
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(handler);
builder.parse("sample.xml");
TestErrorHandlerは各メソッドで標準出力を出すなりしましょう。
一番最初namespaceなしのXMLで検証ができなくて悩んでいましたが、その理由は以下のフラグをfalseにしていたせいでした。
factory.setNamespaceAware(true);
自分が作成したXMLはnamespace使ってないからと思ってましたが、よく考えたらXMLスキーマの指定の部分とかで使ってるんですよね。
**XMLプロセッサ実装の切替え
以下のシステムプロパティに対して使用したい実装のFactoryクラスを指定する。
javax.xml.parsers.SAXParserFactory
javax.xml.parsers.DocumentBuilderFactory
javax.xml.transform.TransformerFactory
例 : WeblogicのDOMパーサを指定する場合
System.setProperty(
"javax.xml.parsers.DocumentBuilderFactory",
"weblogic.xml.jaxp.RegistryDocumentBuilderFactory");
**XMLSchemaによるXML検証
DOMの場合です。
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
TestErrorHandler handler = new TestErrorHandler();
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(handler);
builder.parse("sample.xml");
TestErrorHandlerは各メソッドで標準出力を出すなりしましょう。
一番最初namespaceなしのXMLで検証ができなくて悩んでいましたが、その理由は以下のフラグをfalseにしていたせいでした。
factory.setNamespaceAware(true);
自分が作成したXMLはnamespace使ってないからと思ってましたが、よく考えたらXMLスキーマの指定の部分とかで使ってるんですよね。
SAXの場合はSAXParserFactoryの設定を以下の通りにするとよいらしい。
spfactory.setFeature(
"http://xml.org/sax/features/namespaces", true);
spfactory.setFeature(
"http://xml.org/sax/features/validation", true);
spfactory.setFeature(
"http://apache.org/xml/features/validation/schema", true);
表示オプション
横に並べて表示:
変化行の前後のみ表示: