You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-user@xml.apache.org by Thomas Condon <to...@vrtx.com> on 2003/12/03 22:02:18 UTC

XMLBeans or perhaps just an XML question...

Given the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.vpharm.com/hypervis/xml"
xmlns:hv="http://www.vpharm.com/hypervis/xml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
	<xs:include schemaLocation="HyperVisTypes.xsd"/>
	<xs:element name="msg" type="hv:SocketMessage"/>
</xs:schema>

where hv:SocketMessage is defined as follows:

<xs:complexType name="SocketMessage">
		<xs:sequence>
			<xs:element name="type" type="xs:string" nillable="false"/>
			<xs:element name="body" type="xs:string"/>
			<xs:element name="annotation" type="xs:string"/>
		</xs:sequence>
	</xs:complexType>


should there be anything illegal in setting the body element to a 
string that is the string form of another XML Document?

XMLBeans does not like it when I set the body to be an XML document as 
opposed to a simple string.


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: XMLBeans or perhaps just an XML question...

Posted by Thomas Condon <to...@vrtx.com>.
Unfortunately, using xs:anytype, XMLObject and SimpleValue,  works for 
the case where my <body> is a simple string, but I still have the 
problem for a <body> element whose value is a complete xml document.  
All of its XML element-ness is stripped away just like in the case of 
the simple string.

Any ideas?

Tom Condon
617-444-6621

One important point to understand is that I have no control over the 
creation of this XML document, I am only reading it.
On Dec 4, 2003, at 6:41 PM, David Bau wrote:

> Any XmlObject can be coerced to a SimpleValue (another interface in 
> the same
> package), and from that you can say
>
> ((SimpleValue)xobj).getStringValue();
>
> For a complex type, this will return the text value of the contents 
> with all
> the tags removed (and &lt; entities etc resolved).
>
> David
> ----- Original Message -----
> From: "Thomas Condon" <to...@vrtx.com>
> To: <xm...@xml.apache.org>
> Sent: Thursday, December 04, 2003 6:02 PM
> Subject: [xmlbeans-user] Re: XMLBeans or perhaps just an XML 
> question...
>
>
>> I changed the type to xs:anyType and when I access the XMLObject using
>> toString() I get
>>
>> <xml-fragment xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:hv="http://www.vpharm.com/hypervis/xml">25.0</xml-fragment>
>>
>> How do I just get the 25.0 as a string?
>>
>> Thanks for the help.  It has been invaluable.
>>
>> Tom Condon
>>
>>
>> On Dec 4, 2003, at 4:30 PM, David Bau wrote:
>>
>>> In XML and XML Schema, strings are just strings - they're not allowed
>>> to
>>> contain elements.
>>>
>>> If you were to say something like
>>>
>>> msg.setBody("<foo><bar/></foo>");
>>>
>>> then what you'd get is something like
>>> <body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>
>>>
>>> If you really want whole tags inside an element like <body>, but you
>>> don't
>>> want to constrain what kind of structure you have in there, then what
>>> you
>>> have is the "xs:anyType" type rather than the "xs:string" type.
>>>
>>> I.e., write as follows:
>>>
>>>    <xs:element name="body" type="xs:anyType"/>
>>>
>>> That should do it - then you should be able to copy whole XmlObject 
>>> (or
>>> document) subtrees, complete with subelements and so on, into your
>>> <body>.
>>>
>>> David
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: XMLBeans or perhaps just an XML question...

Posted by Thomas Condon <to...@vrtx.com>.
Unfortunately, using xs:anytype, XMLObject and SimpleValue,  works for 
the case where my <body> is a simple string, but I still have the 
problem for a <body> element whose value is a complete xml document.  
All of its XML element-ness is stripped away just like in the case of 
the simple string.

Any ideas?

Tom Condon
617-444-6621

One important point to understand is that I have no control over the 
creation of this XML document, I am only reading it.
On Dec 4, 2003, at 6:41 PM, David Bau wrote:

> Any XmlObject can be coerced to a SimpleValue (another interface in 
> the same
> package), and from that you can say
>
> ((SimpleValue)xobj).getStringValue();
>
> For a complex type, this will return the text value of the contents 
> with all
> the tags removed (and &lt; entities etc resolved).
>
> David
> ----- Original Message -----
> From: "Thomas Condon" <to...@vrtx.com>
> To: <xm...@xml.apache.org>
> Sent: Thursday, December 04, 2003 6:02 PM
> Subject: [xmlbeans-user] Re: XMLBeans or perhaps just an XML 
> question...
>
>
>> I changed the type to xs:anyType and when I access the XMLObject using
>> toString() I get
>>
>> <xml-fragment xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:hv="http://www.vpharm.com/hypervis/xml">25.0</xml-fragment>
>>
>> How do I just get the 25.0 as a string?
>>
>> Thanks for the help.  It has been invaluable.
>>
>> Tom Condon
>>
>>
>> On Dec 4, 2003, at 4:30 PM, David Bau wrote:
>>
>>> In XML and XML Schema, strings are just strings - they're not allowed
>>> to
>>> contain elements.
>>>
>>> If you were to say something like
>>>
>>> msg.setBody("<foo><bar/></foo>");
>>>
>>> then what you'd get is something like
>>> <body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>
>>>
>>> If you really want whole tags inside an element like <body>, but you
>>> don't
>>> want to constrain what kind of structure you have in there, then what
>>> you
>>> have is the "xs:anyType" type rather than the "xs:string" type.
>>>
>>> I.e., write as follows:
>>>
>>>    <xs:element name="body" type="xs:anyType"/>
>>>
>>> That should do it - then you should be able to copy whole XmlObject 
>>> (or
>>> document) subtrees, complete with subelements and so on, into your
>>> <body>.
>>>
>>> David
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: XMLBeans or perhaps just an XML question...

Posted by David Bau <da...@bea.com>.
Any XmlObject can be coerced to a SimpleValue (another interface in the same
package), and from that you can say

((SimpleValue)xobj).getStringValue();

For a complex type, this will return the text value of the contents with all
the tags removed (and &lt; entities etc resolved).

David
----- Original Message ----- 
From: "Thomas Condon" <to...@vrtx.com>
To: <xm...@xml.apache.org>
Sent: Thursday, December 04, 2003 6:02 PM
Subject: [xmlbeans-user] Re: XMLBeans or perhaps just an XML question...


> I changed the type to xs:anyType and when I access the XMLObject using
> toString() I get
>
> <xml-fragment xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:hv="http://www.vpharm.com/hypervis/xml">25.0</xml-fragment>
>
> How do I just get the 25.0 as a string?
>
> Thanks for the help.  It has been invaluable.
>
> Tom Condon
>
>
> On Dec 4, 2003, at 4:30 PM, David Bau wrote:
>
> > In XML and XML Schema, strings are just strings - they're not allowed
> > to
> > contain elements.
> >
> > If you were to say something like
> >
> > msg.setBody("<foo><bar/></foo>");
> >
> > then what you'd get is something like
> > <body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>
> >
> > If you really want whole tags inside an element like <body>, but you
> > don't
> > want to constrain what kind of structure you have in there, then what
> > you
> > have is the "xs:anyType" type rather than the "xs:string" type.
> >
> > I.e., write as follows:
> >
> >    <xs:element name="body" type="xs:anyType"/>
> >
> > That should do it - then you should be able to copy whole XmlObject (or
> > document) subtrees, complete with subelements and so on, into your
> > <body>.
> >
> > David


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: XMLBeans or perhaps just an XML question...

Posted by David Bau <da...@bea.com>.
Any XmlObject can be coerced to a SimpleValue (another interface in the same
package), and from that you can say

((SimpleValue)xobj).getStringValue();

For a complex type, this will return the text value of the contents with all
the tags removed (and &lt; entities etc resolved).

David
----- Original Message ----- 
From: "Thomas Condon" <to...@vrtx.com>
To: <xm...@xml.apache.org>
Sent: Thursday, December 04, 2003 6:02 PM
Subject: [xmlbeans-user] Re: XMLBeans or perhaps just an XML question...


> I changed the type to xs:anyType and when I access the XMLObject using
> toString() I get
>
> <xml-fragment xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:hv="http://www.vpharm.com/hypervis/xml">25.0</xml-fragment>
>
> How do I just get the 25.0 as a string?
>
> Thanks for the help.  It has been invaluable.
>
> Tom Condon
>
>
> On Dec 4, 2003, at 4:30 PM, David Bau wrote:
>
> > In XML and XML Schema, strings are just strings - they're not allowed
> > to
> > contain elements.
> >
> > If you were to say something like
> >
> > msg.setBody("<foo><bar/></foo>");
> >
> > then what you'd get is something like
> > <body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>
> >
> > If you really want whole tags inside an element like <body>, but you
> > don't
> > want to constrain what kind of structure you have in there, then what
> > you
> > have is the "xs:anyType" type rather than the "xs:string" type.
> >
> > I.e., write as follows:
> >
> >    <xs:element name="body" type="xs:anyType"/>
> >
> > That should do it - then you should be able to copy whole XmlObject (or
> > document) subtrees, complete with subelements and so on, into your
> > <body>.
> >
> > David


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: XMLBeans or perhaps just an XML question...

Posted by Thomas Condon <to...@vrtx.com>.
I changed the type to xs:anyType and when I access the XMLObject using 
toString() I get

<xml-fragment xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:hv="http://www.vpharm.com/hypervis/xml">25.0</xml-fragment>

How do I just get the 25.0 as a string?

Thanks for the help.  It has been invaluable.

Tom Condon


On Dec 4, 2003, at 4:30 PM, David Bau wrote:

> In XML and XML Schema, strings are just strings - they're not allowed 
> to
> contain elements.
>
> If you were to say something like
>
> msg.setBody("<foo><bar/></foo>");
>
> then what you'd get is something like
> <body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>
>
> If you really want whole tags inside an element like <body>, but you 
> don't
> want to constrain what kind of structure you have in there, then what 
> you
> have is the "xs:anyType" type rather than the "xs:string" type.
>
> I.e., write as follows:
>
>    <xs:element name="body" type="xs:anyType"/>
>
> That should do it - then you should be able to copy whole XmlObject (or
> document) subtrees, complete with subelements and so on, into your 
> <body>.
>
> David
> ----- Original Message -----
> From: "Thomas Condon" <to...@vrtx.com>
> To: <xm...@xml.apache.org>
> Sent: Wednesday, December 03, 2003 4:02 PM
> Subject: [xmlbeans-user] XMLBeans or perhaps just an XML question...
>
>
>> Given the following schema:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xs:schema targetNamespace="http://www.vpharm.com/hypervis/xml"
>> xmlns:hv="http://www.vpharm.com/hypervis/xml"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> elementFormDefault="qualified"
>> attributeFormDefault="unqualified">
>> <xs:include schemaLocation="HyperVisTypes.xsd"/>
>> <xs:element name="msg" type="hv:SocketMessage"/>
>> </xs:schema>
>>
>> where hv:SocketMessage is defined as follows:
>>
>> <xs:complexType name="SocketMessage">
>> <xs:sequence>
>> <xs:element name="type" type="xs:string" nillable="false"/>
>> <xs:element name="body" type="xs:string"/>
>> <xs:element name="annotation" type="xs:string"/>
>> </xs:sequence>
>> </xs:complexType>
>>
>>
>> should there be anything illegal in setting the body element to a
>> string that is the string form of another XML Document?
>>
>> XMLBeans does not like it when I set the body to be an XML document as
>> opposed to a simple string.
>>
>>
>> - 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
>> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
>> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>>
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>

Re: XMLBeans or perhaps just an XML question...

Posted by Thomas Condon <to...@vrtx.com>.
I changed the type to xs:anyType and when I access the XMLObject using 
toString() I get

<xml-fragment xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:hv="http://www.vpharm.com/hypervis/xml">25.0</xml-fragment>

How do I just get the 25.0 as a string?

Thanks for the help.  It has been invaluable.

Tom Condon


On Dec 4, 2003, at 4:30 PM, David Bau wrote:

> In XML and XML Schema, strings are just strings - they're not allowed 
> to
> contain elements.
>
> If you were to say something like
>
> msg.setBody("<foo><bar/></foo>");
>
> then what you'd get is something like
> <body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>
>
> If you really want whole tags inside an element like <body>, but you 
> don't
> want to constrain what kind of structure you have in there, then what 
> you
> have is the "xs:anyType" type rather than the "xs:string" type.
>
> I.e., write as follows:
>
>    <xs:element name="body" type="xs:anyType"/>
>
> That should do it - then you should be able to copy whole XmlObject (or
> document) subtrees, complete with subelements and so on, into your 
> <body>.
>
> David
> ----- Original Message -----
> From: "Thomas Condon" <to...@vrtx.com>
> To: <xm...@xml.apache.org>
> Sent: Wednesday, December 03, 2003 4:02 PM
> Subject: [xmlbeans-user] XMLBeans or perhaps just an XML question...
>
>
>> Given the following schema:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xs:schema targetNamespace="http://www.vpharm.com/hypervis/xml"
>> xmlns:hv="http://www.vpharm.com/hypervis/xml"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> elementFormDefault="qualified"
>> attributeFormDefault="unqualified">
>> <xs:include schemaLocation="HyperVisTypes.xsd"/>
>> <xs:element name="msg" type="hv:SocketMessage"/>
>> </xs:schema>
>>
>> where hv:SocketMessage is defined as follows:
>>
>> <xs:complexType name="SocketMessage">
>> <xs:sequence>
>> <xs:element name="type" type="xs:string" nillable="false"/>
>> <xs:element name="body" type="xs:string"/>
>> <xs:element name="annotation" type="xs:string"/>
>> </xs:sequence>
>> </xs:complexType>
>>
>>
>> should there be anything illegal in setting the body element to a
>> string that is the string form of another XML Document?
>>
>> XMLBeans does not like it when I set the body to be an XML document as
>> opposed to a simple string.
>>
>>
>> - 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
>> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
>> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>>
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>

Re: XMLBeans or perhaps just an XML question...

Posted by David Bau <da...@bea.com>.
In XML and XML Schema, strings are just strings - they're not allowed to
contain elements.

If you were to say something like

msg.setBody("<foo><bar/></foo>");

then what you'd get is something like
<body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>

If you really want whole tags inside an element like <body>, but you don't
want to constrain what kind of structure you have in there, then what you
have is the "xs:anyType" type rather than the "xs:string" type.

I.e., write as follows:

   <xs:element name="body" type="xs:anyType"/>

That should do it - then you should be able to copy whole XmlObject (or
document) subtrees, complete with subelements and so on, into your <body>.

David
----- Original Message ----- 
From: "Thomas Condon" <to...@vrtx.com>
To: <xm...@xml.apache.org>
Sent: Wednesday, December 03, 2003 4:02 PM
Subject: [xmlbeans-user] XMLBeans or perhaps just an XML question...


> Given the following schema:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema targetNamespace="http://www.vpharm.com/hypervis/xml"
> xmlns:hv="http://www.vpharm.com/hypervis/xml"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> <xs:include schemaLocation="HyperVisTypes.xsd"/>
> <xs:element name="msg" type="hv:SocketMessage"/>
> </xs:schema>
>
> where hv:SocketMessage is defined as follows:
>
> <xs:complexType name="SocketMessage">
> <xs:sequence>
> <xs:element name="type" type="xs:string" nillable="false"/>
> <xs:element name="body" type="xs:string"/>
> <xs:element name="annotation" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
>
>
> should there be anything illegal in setting the body element to a
> string that is the string form of another XML Document?
>
> XMLBeans does not like it when I set the body to be an XML document as
> opposed to a simple string.
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: XMLBeans or perhaps just an XML question...

Posted by David Bau <da...@bea.com>.
In XML and XML Schema, strings are just strings - they're not allowed to
contain elements.

If you were to say something like

msg.setBody("<foo><bar/></foo>");

then what you'd get is something like
<body>&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;</body>

If you really want whole tags inside an element like <body>, but you don't
want to constrain what kind of structure you have in there, then what you
have is the "xs:anyType" type rather than the "xs:string" type.

I.e., write as follows:

   <xs:element name="body" type="xs:anyType"/>

That should do it - then you should be able to copy whole XmlObject (or
document) subtrees, complete with subelements and so on, into your <body>.

David
----- Original Message ----- 
From: "Thomas Condon" <to...@vrtx.com>
To: <xm...@xml.apache.org>
Sent: Wednesday, December 03, 2003 4:02 PM
Subject: [xmlbeans-user] XMLBeans or perhaps just an XML question...


> Given the following schema:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema targetNamespace="http://www.vpharm.com/hypervis/xml"
> xmlns:hv="http://www.vpharm.com/hypervis/xml"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> <xs:include schemaLocation="HyperVisTypes.xsd"/>
> <xs:element name="msg" type="hv:SocketMessage"/>
> </xs:schema>
>
> where hv:SocketMessage is defined as follows:
>
> <xs:complexType name="SocketMessage">
> <xs:sequence>
> <xs:element name="type" type="xs:string" nillable="false"/>
> <xs:element name="body" type="xs:string"/>
> <xs:element name="annotation" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
>
>
> should there be anything illegal in setting the body element to a
> string that is the string form of another XML Document?
>
> XMLBeans does not like it when I set the body to be an XML document as
> opposed to a simple string.
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/