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"
javax.xml.parsers.DocumentBuilderFactory
$B%7%9%F%`!&%W%m%Q%F%#(Blib/jaxp.properties
META-INF/services/javax.xml.parsers.DocumentBuilderFactory
$B%U%!%$%k(BDocumentBuilderFactory
$B%$%s%9%?%s%9(Bjavax.xml.parsers.DocumentBuilderFactory
$B$K$F!"
>java -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.crimson.jaxp.DocumentBuilderFactoryImpl DomParseDemo3 demo2.xml
>java -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl DomParseDemo3 demo2.xml
DocumentBuilderFactory
$B7?%*%V%8%'%/%H$KBP$7$F!"$5$^$6$^$JB0@-$r%;%C%H$G$-$^$9!#(BXerces$B$G$O%Q!<%58GM-$N(BURI$B$K$h$C$F%U%#!<%A%c!<$r%;%C%H$7$F$$$^$7$?$,!"(BJAXP$B$G$OB0@-8GM-$N%a%=%C%I$,MQ0U$5$l$F$$$^$9!#(BJAXP$B$GMQ0U$5$l$F$$$J$$!"(BXML$B%Q!<%5$N
$B%a%=%C%I(B true$B$N0UL#(B $B>JN,;~CM(B setValidating(boolean value)
$BBEEv@-8!>Z$r9T$&(B false
setNamespaceAware(boolean value)
$BL>A06u4V$rG'<1$9$k(B false
setIgnoringComments(boolean value)
$B%3%a%s%H$rL5;k$9$k(B false
setIgnoringElementContentWhitespace(boolean value)
$BL5;k$G$-$k6uGr$rL5;k$9$k(B false
setAttribute(String name,Object value)
$B;XDj$7$?B0@-$KCM$r%;%C%H$9$k(B n/a
Document
$B%$%s%9%?%s%9$O!"%U%!%/%H%j!&%/%i%9(BDocumentBuilder
$B$K$h$C$F@8@.$7!"(BDocumentBuilder
$B$O(BDocumentBuilderFactory
$B$K$h$C$F@8@.$7$^$9!#@8@.$7$?(BDocumentBuilder
$B$K$O(BErrorHandler
$B$r%;%C%H$9$k$N$,IaDL$G$9!#(B
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new MyHandler());
Document doc = builder.parse(arg[0]);
// $BL>A06u4V$rG'<1$9$k(B
factory.setNamespaceAware(true);
// XML Scehma$B$rG'<1$9$k(B
factory.setAttribute("http://apache.org/xml/features/validation/schema",new Boolean(true));
JAXP$B$N%5%s%W%k(B
import org.w3c.dom.*;
import org.apache.xerces.parsers.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
class DomParseDemo4 {
public static void main(String[] args) {
try {
// DOM$B%Q!<%5MQ%U%!%/%H%j$N@8@.(B
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// $BBEEv@-8!>Z$r9T$&(B
factory.setValidating(true);
// $BL>A06u4V$rG'<1$9$k(B
factory.setNamespaceAware(true);
// XML Scehma$B$rG'<1$9$k(B
factory.setAttribute("http://apache.org/xml/features/validation/schema",true);
// DOM Document$B%$%s%9%?%s%9MQ%U%!%/%H%j$N@8@.(B
DocumentBuilder builder = factory.newDocumentBuilder();
// $B%(%i!
demo5.xml
$B$H$7$F!"F1$8%G%#%l%/%H%j$K(BXML Schema$BJ8=q$G$"$k(B$B%j%9%H(B6$B$r(Baddress.xsd
$B$H$7$FJ]B8$7$^$7$?!#$^$?!"(Bdemo5.xml
$B$N:G=i$N(Bitem$BMWAG$G!"(Bsex$BB0@-$NCM$r(Bman$B$KJQ$($?$b$N(B($B%j%9%H(B11)$B$r8!>Z$9$k$H!"(BXML Schema$B$GL$Dj5A$NB0@-CM(Bman$B$,IT@5$G$"$k;]$,Js9p$5$l$^$9!#(B
<?xml version="1.0" encoding="UTF-8"?>
<hlq:address xmlns:hlq="urn:address"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:address address.xsd">
<hlq:item sex="man" custid="E21099">
<hlq:name>$B?{0f!!3X(B</hlq:name>
...
>javac DomParseDemo4.java
>java DomParseDemo4 demo5.xml
>java DomParseDemo4 demo6.xml
$B%(%i!<(B: 5$B9TL\(B
cvc-enumeration-valid: Value 'man' is not facet-valid with respect to enumeration '[male, female]'. It must be a value from the enumeration.
$B%(%i!<(B: 5$B9TL\(B
cvc-attribute.3: The value 'man' of attribute 'sex' on element 'hlq:item' is not valid with respect to its type, 'null'.
>
Copyright © 2003 SUGAI, Manabu. All Rights Reserved.
SEO
[PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送