|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀüÀÇ ÆÐŰÁö ´ÙÀ½ÀÇ ÆÐŰÁö | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ |
ÂüÁ¶Ã³:
¼³¸í
Ŭ·¡½º °³¿ä | |
---|---|
Schema | ¹®¹ýÀÇ ºÒº¯ÀÇ ¸Þ¸ð¸® ¿ìÄ¡¿À¸ðÅ×Çö. |
SchemaFactory | Schema °´Ã¼¸¦ ÀÛ¼ºÇÏ´Â ÆÑÅ丮. |
SchemaFactoryLoader | SchemaFactory ¸¦
ÀÛ¼ºÇÏ´Â ÆÑÅ丮ÀÔ´Ï´Ù. |
TypeInfoProvider | ÀÌ Å¬·¡½º´Â ValidatorHandler ¿¡ ÀÇÇØ ÆÇÁ¤µÈ ÇüÅ Á¤º¸¿¡ ¾×¼¼½º ÇÕ´Ï´Ù. |
Validator | Schema ¿Í
Á¶ÇÕÇØ XML ¹®¼¸¦ üũÇÏ´Â ÇÁ·Î¼¼¼ÀÔ´Ï´Ù. |
ValidatorHandler | SAX ½ºÆ®¸²¿¡ À¯È¿ÇÑ ½ºÆ®¸®¹Ö ¹ß¸® µ¥ÀÌÅÍ. |
ÀÌ ÆÐŰÁö´Â XML ¹®¼ÀÇ °ËÁõÇϱâ À§ÇÑ API¸¦ Á¦°øÇÕ´Ï´Ù. ¡¸°ËÁõ¡¹À̶õ XML ¹®¼°¡ ÁöÁ¤µÇ¾ú´Ù XML schemaÀÇ ÀνºÅϽºÀÎ °ÍÀ» °ËÁõÇÏ´Â ÇÁ·Î¼¼½ºÀÔ´Ï´Ù. XML schema´Â ±× ÀνºÅϽº ¹®¼°¡ ³ªÅ¸³»´Â ÄÁÅÙÃ÷ ¸ðµ¨ ( ¡¸¹®¹ý¡¹¶Ç´Â ¡¸º¸Ä³ºê¶ó¸®¡¹¶ó°íµµ ºÒ¸°´Ù)¸¦ Á¤ÀÇÇÕ´Ï´Ù.
XML schemaÀÇ ÀÛ¼º¿¡´Â ³Ð°Ô ÀÌ¿ëµÇ°í ÀÖ´Â Àü¹® ¾ð¾î°¡ ¸¹ÀÌ Á¸ÀçÇÕ´Ï´Ù. ±× Áß¿¡¼ °¡Àå ´ëÇ¥ÀûÀÎ ¾ð¾î´Â ´ÙÀ½°ú °°½À´Ï´Ù.
ÀÌÀüÀÇ ¹öÀüÀÇ JAXP´Â
SAXParser
¶Ç´Â DocumentBuilder
ÀνºÅϽº·Î ³ªÅ¸³»Áö´Â XML
ÆÄ¼ÀÇ ±â´ÉÀ¸·Î¼ÀÇ °ËÁõÀ» Áö¿ø
Çϰí ÀÖ¾ú½À´Ï´Ù.
JAXP °ËÁõ API´Â XML ¹®¼ÀÇ ±¸¹® ºÐ¼®À¸·ÎºÎÅÍ ÀνºÅϽº ¹®¼ÀÇ °ËÁõÀ» ºÐ¸®ÇÕ´Ï´Ù. À̰ÍÀÌ µµ¿òÀÌ µÇ´Â °ÍÀº ´ÙÀ½°ú °°Àº ÀÌÀ¯·ÎºÎÅÍÀÔ´Ï´Ù.
»ç¿ë·Ê Â÷ÀÇ ¿¹´Â °ËÁõ API¸¦ »ç¿ëÇß´Ù XML ¹®¼ÀÇ °ËÁõÀ» ³ªÅ¸³»°í ÀÖ½À´Ï´Ù. Àб⠽¬¿òÀ» °í·ÁÇØ, ÀϺÎÀÇ ¿¹¿Ü 󸮴 ±âÀçµÇ¾î ÀÖÁö ¾Ê½À´Ï´Ù.
// parse an XML document into a DOM tree DocumentBuilder parser = DocumentBuilderFactory.newInstance(). newDocumentBuilder(); Document document = parser.parse(new File("instance.xml"));// create a SchemaFactory capable of understanding WXS schemas SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance Source schemaFile = new StreamSource(new File("mySchema.xsd")); Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an instance document Validator validator = schema.newValidator();
// validate the DOM tree try { validator.validate(new DOMSource(document)); } catch (SAXException e) { // instance document is invalid! }
JAXP ±¸¹® ºÐ¼® API´Â
°ËÁõ API¿¡ ÅëÇյǰí ÀÖ½À´Ï´Ù. ¾îÇø®ÄÉÀ̼ÇÀº °ËÁõ API¸¦ »ç¿ëÇØ Schema
¸¦
ÀÛ¼ºÇØ, À̰ÍÀ» DocumentBuilderFactory.setSchema(Schema)
¹× SAXParserFactory.setSchema(Schema)
¸Þ¼µå¸¦ »ç¿ëÇØ DocumentBuilderFactory
¶Ç´Â SAXParserFactory
ÀνºÅϽº¿¡ °ü·ÃÁþ½À´Ï´Ù. 1°³ÀÇ ÆÄ¼ ÆÑÅ丮·Î schemaÀÇ ¼³Á¤°ú
setValidating(true)
È£ÃâÀÇ ¾çÂÊ ¸ðµÎ¸¦½Ç½ÃÇÏÁö ¸»¾Æ ÁÖ¼¼¿ä. ½º
۸¶¸¦ ¼³Á¤Çϸé, ÆÄ¼´Â »õ·Î¿î °ËÁõ API¸¦ »ç¿ëÇØ, setValidating(true)
¸¦ È£ÃâÇϸé, ÆÄ¼´Â ÀÚ½ÅÀÇ ³»ºÎ °ËÁõ ±â´ÉÀ» »ç¿ëÇÕ´Ï´Ù. ÀÌ 2
°³ÀÇ ¿É¼ÇÀ» µ¿½Ã¿¡ À¯È¿ÇÏ°Ô Çϸé, ÀåȲ µ¿ÀÛ ¶Ç´Â ¿¡·¯ÀÇ ¿øÀÎÀÌ µË´Ï´Ù.
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀüÀÇ ÆÐŰÁö ´ÙÀ½ÀÇ ÆÐŰÁö | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ |
Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy µµ ÂüÁ¶ÇϽʽÿÀ.