2009-04-10 3 views
0

내 XSD 파일이 포함되어 XML 빈스와XML 빈스 - 복잡한 유형의 설정 내용

   <xs:sequence> 
        <xs:element name="Book"> 
         <xs:complexType> 
          <xs:attribute name="author" type="xs:string" /> 
          <xs:attribute name="title" type="xs:string" /> 
         </xs:complexType> 
        </xs:element> 
       </xs:sequence> 

, 내가 사용 쉽게 속성을 설정할 수 있습니다 :

Book book= books.addNewBook(); 
    book.setTitle("The Lady and a Little Dog"); 

은 내가 newCursor를 사용할 수 있다는 것을 알고() 요소의 내용을 설정하는 것이 가장 좋은 방법입니까?

object.newCursor().setTextValue(builer.toString()); 

답변

1

나는 당신의 질문을 이해하지 못합니다.

나는 당신의 XSD는 다음과 같이 XML을 생성하는 당신에게 자바 클래스를 줄 것이라고 생각 :

<book author="Fred" title="The Lady and a Little Dog" /> 

당신이 당신과 같은 XML로 끝날 수 있도록, XML 요소 내에서 "내부"텍스트를 설정하려는 뜻 이?

Book book= books.addNewBook(); 
book.setAuthor("Fred"); 
book.setTitle("The Lady and a Little Dog"); 

: 그럼 당신은 간단하게 할 수 있습니다

<xs:sequence> 
    <xs:element name="Book"> 
     <xs:complexType> 
      <xs:sequence> 
      <xs:element name="author" type="xs:string" /> 
      <xs:element name="title" type="xs:string" /> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
</xs:sequence> 

: 그렇다면

<book> 
    <author>Fred</author> 
    <title>The Lady and a Little Dog</title> 
</book> 

은이에 XSD를 변경 속성보다는 중첩 된 요소를 사용하는

업데이트

확인 - 이제는 이해합니다. 다음

<xs:element name="Book" minOccurs="0" maxOccurs="unbounded"> 
    <xs:complexType> 
    <xs:simpleContent> 
     <xs:extension base="xs:string"> 
     <xs:attribute name="author" type="xs:string" /> 
     <xs:attribute name="title" type="xs:string" /> 
     </xs:extension> 
    </xs:simpleContent> 
    </xs:complexType>  
</xs:element> 

을 그리고 :

이 시도

당신이 원하는 어느 제가 생각이 같은 XML을 제공해야
Book book1 = books.addNewBook(); 
    book1.setAuthor("Fred"); 
    book1.setTitle("The Lady and a Little Dog"); 
    book1.setStringValue("This is some text"); 

    Book book2 = books.addNewBook(); 
    book2.setAuthor("Jack"); 
    book2.setTitle("The Man and a Little Cat"); 
    book2.setStringValue("This is some more text"); 

:

<Book author="Fred" title="The Lady and a Little Dog">This is some text</Book> 
<Book author="Jack" title="The Man and a Little Cat">This is some more text</Book> 
+0

이것은 내가 무엇을 것입니다 내 xml처럼 보이게 : 이것은 일부 텍스트입니다 어떻게"This is some text "비트를 넣을 수 있습니까? 감사합니다. – dogbane

+0

답변을 업데이트했습니다. 더 도움이 되었기를 바랍니다. –

0

나는 이것이 당신이 요구하고 있지만 속성이나 XML 빈스를 사용하여 요소의 값을 설정하는 가장 좋은 방법은 XML 빈스 생성 된 getter 및 setter를 사용하는 것입니다 정확히입니다 있는지 확실하지 않습니다.

커서 질문에 대한 상황이 조금 더 도움이 될 수 있습니다.