You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Paul Tomsic <pt...@yahoo.com> on 2006/07/11 19:57:20 UTC

best way to handle mixed content?

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: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: best way to handle mixed content?

Posted by Yang ZHONG <le...@gmail.com>.
sub-elements can be processed as Property and element content can be
processed as Property value.

If you want to process everything as raw text, as far as I can tell, that's
not really SDO Programming Model.


On 7/11/06, Paul Tomsic <pt...@yahoo.com> wrote:
>
> 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 <le...@gmail.com> wrote:
>
> > Maybe you can try sampleText.getSequence( "mixed")
> >
> > On 7/11/06, Paul Tomsic <pt...@yahoo.com> 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:
> > tuscany-dev-unsubscribe@ws.apache.org
> > > For additional commands, e-mail:
> > tuscany-dev-help@ws.apache.org
> > >
> > >
> >
> >
> > --
> >
> > Yang ZHONG
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>
>


-- 

Yang ZHONG

Re: best way to handle mixed content?

Posted by Robbie J Minshall <rj...@us.ibm.com>.
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
     * {@link #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 {@link #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 <pt...@yahoo.com> 
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 <le...@gmail.com> wrote:

> Maybe you can try sampleText.getSequence( "mixed")
> 
> On 7/11/06, Paul Tomsic <pt...@yahoo.com> 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:
> tuscany-dev-unsubscribe@ws.apache.org
> > For additional commands, e-mail:
> tuscany-dev-help@ws.apache.org
> >
> >
> 
> 
> -- 
> 
> Yang ZHONG
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org



Re: best way to handle mixed content?

Posted by Frank Budinsky <fr...@ca.ibm.com>.
So you just want the raw XML? If you don't want it parsed into an object 
model, why are you using SDO in the first place? 

You can get an XML serialization of a DataObject by calling 
XMLHelper.save().

Frank.

Paul Tomsic <pt...@yahoo.com> wrote on 07/11/2006 02:29:00 PM:

> 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 <le...@gmail.com> wrote:
> 
> > Maybe you can try sampleText.getSequence( "mixed")
> > 
> > On 7/11/06, Paul Tomsic <pt...@yahoo.com> 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:
> > tuscany-dev-unsubscribe@ws.apache.org
> > > For additional commands, e-mail:
> > tuscany-dev-help@ws.apache.org
> > >
> > >
> > 
> > 
> > -- 
> > 
> > Yang ZHONG
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: best way to handle mixed content?

Posted by Paul Tomsic <pt...@yahoo.com>.
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 <le...@gmail.com> wrote:

> Maybe you can try sampleText.getSequence( "mixed")
> 
> On 7/11/06, Paul Tomsic <pt...@yahoo.com> 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:
> tuscany-dev-unsubscribe@ws.apache.org
> > For additional commands, e-mail:
> tuscany-dev-help@ws.apache.org
> >
> >
> 
> 
> -- 
> 
> Yang ZHONG
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: best way to handle mixed content?

Posted by Frank Budinsky <fr...@ca.ibm.com>.
That should actually be 

    sampleText.getSequence()

that is, no arguments to the getSequence call. The getSequenced("mixed") 
API is Tuscany-specific and the SDO spec is considering deprecating it 
(and the other getSequence methods that take an argument) from the 
DataObject API.

The "proper" SDO API for accessing the content of a mixed type is to call 
getSequence() and then iterate through the property/value entries, as 
Raymond said in his reply.

Frank.

"Yang ZHONG" <le...@gmail.com> wrote on 07/11/2006 02:05:19 
PM:

> Maybe you can try sampleText.getSequence( "mixed")
> 
> On 7/11/06, Paul Tomsic <pt...@yahoo.com> 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: tuscany-dev-unsubscribe@ws.apache.org
> > For additional commands, e-mail: tuscany-dev-help@ws.apache.org
> >
> >
> 
> 
> -- 
> 
> Yang ZHONG


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: best way to handle mixed content?

Posted by Yang ZHONG <le...@gmail.com>.
Maybe you can try sampleText.getSequence( "mixed")

On 7/11/06, Paul Tomsic <pt...@yahoo.com> 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: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>
>


-- 

Yang ZHONG

Re: best way to handle mixed content?

Posted by Raymond Feng <en...@gmail.com>.
The mixed content can be accessed using SDO Sequence (property/value pairs). 
I observed that for pure text, the corresponding property is null.

Thanks,
Raymond

----- Original Message ----- 
From: "Paul Tomsic" <pt...@yahoo.com>
To: <tu...@ws.apache.org>
Sent: Tuesday, July 11, 2006 10:57 AM
Subject: best way to handle mixed content?


> 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: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org