WebSphere Enterprise Service Bus, 버전 6.2.0 운영 체제: AIX, HP-UX, i5/OS, Linux, Solaris, Windows


Any 값 가져오기/설정 방법

Any 필드에 설정된 데이터 이름을 알고 있는 경우 기타 요소 값과 동일한 방법으로 데이터 가져오기를 수행할 수 있습니다.

XPath "<이름>"을 사용하여 가져오기를 수행할 수 있으며 가져오기가 해결됩니다. 이름을 알 수 없는 경우에는 앞에서와 마찬가지로 인스턴스 특성을 확인하여 값을 찾을 수 있습니다. any 태그가 여러 개 있거나 maxOccurs > 1인 any 태그가 있는 경우 데이터를 가져온 원본 any 태그를 판별하는 일이 중요하면 DataObject 순서를 대신 사용해야 합니다.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:tns="http://AnyElemAny" 
 targetNamespace="http://AnyElemAny">
  <xsd:complexType name="AnyElemAny">
    <xsd:sequence>
      <!-- Handle all these any one way -->
      <xsd:any maxOccurs="3"/>
      <xsd:element name="marker1" type="xsd:string"/>
      <!-- Handle this any in another -->
      <xsd:any/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

<any/> 태그로 인해 DataObject 순서가 지정되므로 any 특성 위치의 순서를 확인하여 설정된 any 값을 판별할 수 있습니다.

다음 코드를 사용하여 다음과 같은 XSD의 인스턴스 데이터가 속하는 any 태그를 판별할 수 있습니다.

	DataObject anyElemAny = ...
	Seqeuence seq = anyElemAny.getSequence();
	
	// Until we encounter the marker1 element, all the open data
	// found belongs to the first any tag
	boolean foundMarker1 = false;
	
	for (int i=0; i<seq.size(); i++)
	{
	    Property prop = seq.getProperty(i);
	    
	    // Check to see if the property is an open property
	    if (prop.isOpenContent())
	    {
	        if (!foundMarker1)
	        {
	            // Must be the first any because it occurs
	            // before the marker1 element
	            System.out.println("Found first any data: "+seq.getValue(i)); 
	        }
	        else
	        {
	            // Must be the second any because it occurs
	            // after the marker1 element
	            System.out.println("Found second any data: "+seq.getValue(i));
	         }
	    }
	    else
	    {
	        // Must be the marker1 element
	        System.out.println("Found marker1 data: "+seq.getValue(i));
	        foundMarker1 = true;
	    }
	}

글로벌 요소 특성을 작성하고 해당 값을 순서에 추가하여 <any/> 값을 설정합니다.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
	xmlns:tns="http://GlobalElems" 
	targetNamespace="http://GlobalElems">
  <xsd:element name="globalElement1" type="xsd:string"/>
  <xsd:element name="globalElement2" type="xsd:string"/>
</xsd:schema>

	DataObject anyElemAny = ...
	Seqeuence seq = anyElemAny.getSequence();

	// Get the global element Property for globalElement1
	Property globalProp1 = boXsdHelper.getGlobalProperty(http://GlobalElems, 
	"globalElement1", true);

	// Get the global element Property for globalElement2
	Property globalProp2 = boXsdHelper.getGlobalProperty(http://GlobalElems, 
	"globalElement2", true);

	// Add the data to the sequence for the first any
	seq.add(globalProp1, "foo");
	seq.add(globalProp1, "bar");
	
	// Add the data for the marker1
	seq.add("marker1", "separator");  // or anyElemAny.set("marker1", "separator")
	
	// Add the data to the sequence for the second any
	seq.add(globalProp2, "baz");

	// The data can now be accessed by a get call
	System.out.println(dobj.get("globalElement1"); // Displays "[foo, bar]"
	System.out.println(dobj.get("marker1");        // Displays "separator"
	System.out.println(dobj.get("globalElement2"); // Displays "baz"

concept 개념 주제

이용약관 | 피드백


시간소인 아이콘 마지막 갱신 날짜: 2010년 7월 7일 수요일


http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r2mx/topic//com.ibm.websphere.wesb620.doc/doc/cbo_howgetsetany.html
Copyright IBM Corporation 2005, 2010. All Rights Reserved.
이 Information Center는 Eclipse 기술을 기반으로 합니다(http://www.eclipse.org 웹 사이트 참조).