본문 바로가기

Programming

xml & xml schema(xsd) association

1. Preparsing:

You can use the Xerces XMLGrammarPreparser to parse your schema to an XSGrammar Object (please refer to the xni.GrammarBuilder sample). Then you can put it in a grammar pool, and set the pool onto the parser.

To examine various properties of the components, you can convert the schema grammar to an XSModel (using the toXSModel method), and use methods defined on XSModel and other related interfaces.

2. PSVI

One of the FAQs [1] describes how to use PSVI in DOM. If you build a PSVI DOM, you can check which elements/attributes are valid, and the element/attribute declarations and type definitions used to validate these nodes. In your example, you can find the invalid node, get its type definition, and examine the enumeration values.

[1] http://xml.apache.org/xerces2-j/faq-xs.html#faq-5

---------------------------------------------------------------------------------------------
parser.setGenerateSyntheticAnnotations(true);
//or, if using SAX2 or DomBuilder
parser.setFeature(XMLUni::fgXercesGenerateSyntheticAnnotations,true);

// parse your file with validation on

GrammarResolver* r=parser.getGrammarResolver();
SchemaGrammar* g=(SchemaGrammar*)r->getGrammar("urn:my:namespace");
XMLElementDecl*
elem=g->getElemDecl(r->getStringPool()->getId("urn:my:namespace"),
"titel", 0, Grammar::TOP_LEVEL_SCOPE);
XSAnnotation* a=g->getAnnotation(elem);
XMLCh* text=a->getAnnotationString();

-------------------------------------------------------------------------------------------
SchemaElementDecl*
books=(SchemaElementDecl*)g->getElemDecl(r->getStringPool()->getId("urn:my:namespace"),

"books", 0, Grammar::TOP_LEVEL_SCOPE);

SchemaElementDecl*
book=(SchemaElementDecl*)g->getElemDecl(r->getStringPool()->getId("urn:my:namespace"),

"book", 0, books->getComplexTypeInfo()->getScopeDefined());

SchemaElementDecl*
title=(SchemaElementDecl*)g->getElemDecl(r->getStringPool()->getId("urn:my:namespace"),

"title", 0, book->getComplexTypeInfo()->getScopeDefined());
---------------------------------------------------------------------------------------------
DOMPSVITypeInfo *typeInfo =
(DOMPSVITypeInfo*)domNode->getInterface(XMLUni::fgXercescInterfacePSVITypeInfo);
const XMLCh *typeName =
typeInfo->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name);
const XMLCh *typeURI =
typeInfo->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace);



'Programming' 카테고리의 다른 글

Windows 2000 공유 해결 방법  (0) 2009.03.24
iptables  (0) 2008.11.17
코드 검색 사이트  (0) 2008.11.08
윈도우에서 XSLT 사용시 주의할점  (0) 2008.10.28
윈도우에서 유닉스로 이식하기, Part 1: C/C++ 이식  (0) 2008.10.20