시퀀스 유형 사용

함수의 리턴 또는 매개변수 유형에 대한 변수를 선언하는 경우 시퀀스 유형을 사용할 수 있습니다.

이 태스크 정보

XML API에서 시퀀스 유형은 XSequenceType 오브젝트를 사용하여 표시합니다. XSequenceType 오브젝트는 XPath 2.0에 정의된 SequenceType 구문과 동일한 시퀀스 유형 세트를 표시할 수 있습니다. XSequenceType 오브젝트는 XSequenceTypeFactory 인터페이스를 통해 작성됩니다. XFactory 인스턴스에서 getSequenceTypeFactory() 메소드를 사용하여 XSequenceTypeFactory의 인스턴스를 확보할 수 있습니다.

프로시저

표 1. XSequenceTypeFactory 메소드 및 시퀀스 유형의 예제. 다음 표에서는 XSequenceTypeFactory의 각 메소드를 나열하고 각각 작성할 수 있는 시퀀스 유형의 예제를 제공합니다(SequenceType 구문 사용).
메소드 서명 시퀀스 유형 예제 주석
emptySequence() empty-sequence()  
item(OccurrenceIndicator cardinality) item()*  
atomic(QName typeName, OccurrenceIndicator cardinality) xs:integer "sc:type"은 사용자 정의 스키마 유형을 참조하는 QName입니다.
sc:type+
documentNode(OccurrenceIndicator cardinality) document-node()?  
documentNodeWithElement(QName elementNameOrWildcard, QName typeName, boolean nillable, OccurrenceIndicator cardinality) document-node(element()) "ns:elem"은 요소 이름을 나타내는 QName이고 "sc:type"은 사용자 정의 스키마 유형을 나타내는 QName입니다.

elementNameOrWildcard 및 typeName 매개변수는 선택사항이며, 요소 이름 또는 유형이 중요하지 않으면 널을 사용합니다.

document-node(element(ns:elem))?
document-node(element(*, sc:type?))
documentNodeWithSchemaElement(QName elementName, OccurrenceIndicator cardinality) document-node(schema-element(sc:elemDecl)) "sc:elemDecl"은 스키마에서 글로벌 요소 선언을 참조하는 QName입니다.
element(QName elementNameOrWildcard, QName typeName, boolean nillable, OccurrenceIndicator cardinality) element(*) "ns:elem"은 요소 이름을 나타내는 QName이고 "sc:type"은 사용자 정의 스키마 유형을 나타내는 QName입니다.

elementNameOrWildcard 및 typeName 매개변수는 선택사항이며, 요소 이름 또는 유형이 중요하지 않으면 널을 사용합니다.

element(ns:elem, sc:type)*
attribute(QName attributeNameOrWildcard, QName typeName, OccurrenceIndicator cardinality) attribute()+ "ns:attrib"는 속성 이름을 나타내는 QName입니다.

attributeNameOrWildcard 및 typeName 매개변수는 선택사항이며, 속성 이름 또는 유형이 중요하지 않으면 널을 사용합니다.

attribute(ns:attrib)
attribute(ns:attrib, xs:string)?
schemaElement(QName elementName, OccurrenceIndicator cardinality) schema-element(sc:elemDecl)* "sc:elemDecl"은 스키마에서 글로벌 요소 선언을 참조하는 QName입니다.
schemaAttribute(QName attributeName, OccurrenceIndicator cardinality) schema-attribute(sc:attribDecl) "sc:attribDecl"은 스키마에서 글로벌 속성 선언을 참조하는 QName입니다.
processingInstruction(QName piNCName, OccurrenceIndicator cardinality) processing-instruction()? "pinst"는 처리 명령어 이름을 나타내는 NCName입니다.
processing-instruction("pinst")
processing-instruction(pinst)
comment(OccurrenceIndicator cardinality) comment()  
text(OccurrenceIndicator cardinality) text()+  
node(OccurrenceIndicator cardinality) node()*  
다음 예제는 다양한 시퀀스 유형을 표시하기 위해 XSequenceType 오브젝트를 작성하는 방법을 보여줍니다. 일부 결과는 스키마에서 유형 및 선언을 참조합니다. 예제에서는 schemaSource 소스 오브젝트를 통해 스키마가 사용 가능하다고 가정합니다.
// Create the factory
XFactory factory = XFactory.newInstance();

// Obtain an XSeqeuenceTypeFactory instance
XSequenceTypeFactory stFactory = factory.getSequenceTypeFactory();

// Create a sequence type for a sequence of xs:integer values: "xs:integer*"
XSequenceType integerSequenceType = stFactory.atomic(
        XTypeConstants.INTEGER_QNAME,
        XSequenceType.OccurrenceIndicator.ZERO_OR_MORE);

// Create a sequence type for a single node: "node()"
XSequenceType nodeType = stFactory.node(OccurrenceIndicator.ONE);

// Define a constant for the target namespace of a schema containing user-defined types and declarations
final String targetNamespace = "http://www.example.org/schema/";

// Register the schema with the XFactory
factory.registerSchema(schemaSource);

// Create a sequence type for exactly one document node with an element of type "employeeRecord" from the schema:
// "document-node(element(*, ns:employeeRecord))"
XSequenceType employeeRecordDocumentType = stFactory.documentNodeWithElement(
        null, 
        new QName(targetNamespace, "employeeRecord"),
        false,
        XSequenceType.OccurrenceIndicator.ONE);

// Create a sequence type for an optional attribute matching the attribute declaration "type" in the schema:
// "schema-attribute(ns:type)?"
XSequenceType optionalEmployeeType = stFactory.schemaAttribute(
        new QName(targetNamespace, "type"),
        XSequenceType.OccurrenceIndicator.ZERO_OR_ONE);

// Create a sequence type for one or more atomic values of type "telephoneNumber" from the schema:
// "ns:telephoneNumber+"
XSequenceType telephoneNumbersType = stFactory.atomic(
        new QName(targetNamespace, "telephoneNumber"),
        XSequenceType.OccurrenceIndicator.ONE_OR_MORE);
샘플 스키마의 컨텐츠:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://www.example.org/schema/" targetNamespace="http://www.example.org/schema/">
    <complexType name="employeeRecord">
        <sequence>
            <element name="name" type="string"></element>
            <element name="id" type="int"></element>
            <element name="telephone" type="ns:telephoneNumber"></element>
        </sequence>
        <attribute ref="ns:type"></attribute>
    </complexType>

    <simpleType name="telephoneNumber">
        <restriction base="string">
            <pattern value="\d{3}-\d{3}-\d{4}"></pattern>
        </restriction>
    </simpleType>

    <element name="employee" type="ns:employeeRecord"></element>

    <simpleType name="employeeType">
        <restriction base="string">
            <enumeration value="full-time"></enumeration>
            <enumeration value="part-time"></enumeration>
            <enumeration value="seasonal"></enumeration>
        </restriction>
    </simpleType>

    <attribute name="type" type="ns:employeeType"></attribute>
</schema>

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=txml_sequence_types
파일 이름:txml_sequence_types.html