Hi.

In one of the examples that I looked at I got a Sequence containing mixed 
text and looped through it as your mentioned.  I performed a check to see 
when the Property was null which would indicate that the value would be 
unstructured text.

I am not sure if that helped - probably it was something you already knew 
and hoped that there would be something better.   I don't know if it will 
help but the following is what I have done :


AccessingTheContentsOfASequence example based on spec example:

The example I played with came from the specification.  I used the 
following xml 
<?xml version="1.0" encoding="ASCII"?>
<letter:letters xmlns:letter="letter.xsd"><date>August 1, 2003</date>
Mutual of Omaha Wild Kingdom, USA Dear<firstName>Casy
</firstName><lastName>Crocodile</lastName>Please buy more shark repellent. 
 Your premium is past due.</letter:letters>


and the following xsd: 

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema     xmlns:letter="letter.xsd" targetNamespace="letter.xsd" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
 
        <xsd:element name="letters" type="letter:FormLetter"/>
        <xsd:complexType name="FormLetter" mixed="true">
                <xsd:sequence>
                        <xsd:element name="date" minOccurs="0" type=
"xsd:string"/>
                        <xsd:element name="firstName" minOccurs="0" type=
"xsd:string"/>
                        <xsd:element name="lastName" minOccurs="0" type=
"xsd:string"/>
                </xsd:sequence>
        </xsd:complexType> 
</xsd:schema>

I simply grabbed the unstructured text out of the letter and printed it 
out.  Then performed a pretty useless check that verifies that the 
lastName property of the DataObject is the same as the one obtained via 
the sequence. 
 /**
     * Uses the Sequence interface to analyze the contents of a DataObject 
that conforms to teh Letter model defined in
     * [EMAIL PROTECTED] #LETTER_XSD}. This code first goes through the 
Sequence 
looking for unformatted text entrires and prints them out. Then the code 
checks
     * to verify that the contents of the "lastName" property of the 
DataObject matches the contents of the same property of the Sequence. <br>
     * 
     * @param letter.  Letter DataObject conforming to [EMAIL PROTECTED] 
#LETTER_XSD}
     */
    public static void printSequence(DataObject letter) {
        // Access the Sequence of the FormLetter
        System.out.println("The type is for letter dataObject is mixed " + 
XSDHelper.INSTANCE.isMixed(letter.getType()));
 
        Sequence letterSequence = letter.getSequence();
        // Print out all the unstructured text
        System.out.println("Unstructured text:");
        for (int i = 0; i < letterSequence.size(); i++) {

            /*
             * Please note that the following line is a correction to the 
2.0 specification which incorrectly calls:
             * 
             * String propertyName = ((Property) 
letterSequence.getProperty(i)).getName();
             * 
             * According to the SDO API sequence.getProperty will return 
null if the content is mixed, in this case
             * we want to print it out as unstructured text 
             */
            Property prop = letterSequence.getProperty(i);  
            if (prop == null) {
                String text = (String) letterSequence.getValue(i);
                System.out.println("\t(" + text + ")");
            }
 
        }

        /*
         * Please note that the following line is a correction to the 2.0 
Specification which uses the letterDataObject variable rather than
         * simply letter
         */
        // Verify that the lastName property of the DataObject has the 
same
        // value as the lastName property for the Sequence.
        String dataObjectLastName = letter.getString("lastName");
        for (int i = 0; i < letterSequence.size(); i++) {

            /*
             * The following line has been corrected from the 2.0 
specification
             * According to the SDO API sequence.getProperty will return 
null if the content is mixed.
                 *
             * We want to check that the content is not mixed, and then 
check that it it is the property which 
             * we are looking for
             */
            Property property = letterSequence.getProperty(i);
 
            if ( (property != null) && ("lastName"
.equals(property.getName()))) {
                String sequenceLastName = (String) 
letterSequence.getValue(i);
                if (dataObjectLastName == sequenceLastName)
                    System.out.println("Last Name property matches");
                break;
            }
        }
    }







Paul Tomsic <[EMAIL PROTECTED]> 
07/11/2006 02:29 PM
Please respond to
tuscany-dev@ws.apache.org


To
tuscany-dev@ws.apache.org
cc

Subject
Re: best way to handle mixed content?






but w/ the Sequence that's returned, i've got a
BasicSequence.  Iterating across it, and doing
sequence.getValue(0) (or 1,2,3, etc) you still need to
handle the sub-elements that are not TEXT type nodes,
right?
Seems like there should be an easier way to do this.
Does anyone have an example of retrieving mixed
content?


--- Yang ZHONG <[EMAIL PROTECTED]> wrote:

> Maybe you can try sampleText.getSequence( "mixed")
> 
> On 7/11/06, Paul Tomsic <[EMAIL PROTECTED]> wrote:
> >
> > Given the following XML, what would be the best
> way to
> > retrieve all of the contents within an element
> that
> > contains mixed content?
> >
> > for instance, in this XML, i'd like to retrieve
> > everything contained within the 'sampleText' node:
> >
> > "Testing sample<em>text</em>with example
> > of<strong>mixed<em>content</em></strong>"
> >
> >
> > here's the XML...
> >
> >
> > ------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> > <foowrapper
> > xmlns="http://www.example.com/mixedcontent";
> >
>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> >
>
xsi:schemaLocation="http://www.example.com/mixedcontent
> > foo.xsd">
> >        <sampleText>Testing sample
> >        <em>text</em>
> >        with example of
> >        <strong>mixed
> >            <em>content</em>
> >                </strong>
> >        </sampleText>
> > </foowrapper>
> >
> >
> > ------------------------
> >
> >
> > thanks
> >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > For additional commands, e-mail:
> [EMAIL PROTECTED]
> >
> >
> 
> 
> -- 
> 
> Yang ZHONG
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to