Discussion:
How can I access a property containing a hyphen (i.e. "portfolio-id")
Harm Bandstra
2007-11-09 20:16:33 UTC
Permalink
Hello All,

I'm not sure if this is the right place for my question, but here
goes...

I have an XSD file with properties containing hyphens. I can't get it
to accept any changes to the properties. In part this is because php
doesn't accept hypens in variable names, but I found that "Simple-XML"
uses some sort of work around. I have the following php code:

===

$xmldas = SDO_DAS_XML::create('xsd/pre_qual_wso.xsd');
$messagebody = $xmldas->createDataObject('','MessagebodyType');

// This gives a syntax error (duh)
$messagebody->portfolio-id = 'BST';

// These 2 give the following error:
// Problem creating an XML document: DataObjectImpl::setSDOValue -
path not found:
$messagebody['portfolio-id'] = 'BST';
$messagebody[0] = 'BST';

// This is the way it's done in simple-xml, but also doesn't work
$messagebody->{'portfolio-id'} = 'BST';

===

Can it be done? Any help will be appreciated.


Kind regards,

Harm Bandstra
simonslaws-gM/Ye1E23mwN+
2007-11-09 21:21:44 UTC
Permalink
Post by Harm Bandstra
Hello All,
I'm not sure if this is the right place for my question, but here
goes...
I have an XSD file with properties containing hyphens. I can't get it
to accept any changes to the properties. In part this is because php
doesn't accept hypens in variable names, but I found that "Simple-XML"
===
$xmldas = SDO_DAS_XML::create('xsd/pre_qual_wso.xsd');
$messagebody = $xmldas->createDataObject('','MessagebodyType');
// This gives a syntax error (duh)
$messagebody->portfolio-id = 'BST';
// Problem creating an XML document: DataObjectImpl::setSDOValue -
$messagebody['portfolio-id'] = 'BST';
$messagebody[0] = 'BST';
// This is the way it's done in simple-xml, but also doesn't work
$messagebody->{'portfolio-id'} = 'BST';
===
Can it be done? Any help will be appreciated.
Kind regards,
Harm Bandstra
Hi Harm

Yep, you found the right place to ask the question. I don't know the
answer off the top of my head and I'm in the middle of rebuilding my
PHP environment today so I'll take a look when I get it sorted. Sorry
about the slight delay. I'll get back to you shortly.

In the mean tim, if anyone else knows the answer feel free to jump
in:-)

Regards

Simon
simonslaws-gM/Ye1E23mwN+
2007-11-14 12:44:07 UTC
Permalink
Post by simonslaws-gM/Ye1E23mwN+
Post by Harm Bandstra
Hello All,
I'm not sure if this is the right place for my question, but here
goes...
I have an XSD file with properties containing hyphens. I can't get it
to accept any changes to the properties. In part this is because php
doesn't accept hypens in variable names, but I found that "Simple-XML"
===
$xmldas = SDO_DAS_XML::create('xsd/pre_qual_wso.xsd');
$messagebody = $xmldas->createDataObject('','MessagebodyType');
// This gives a syntax error (duh)
$messagebody->portfolio-id = 'BST';
// Problem creating an XML document: DataObjectImpl::setSDOValue -
$messagebody['portfolio-id'] = 'BST';
$messagebody[0] = 'BST';
// This is the way it's done in simple-xml, but also doesn't work
$messagebody->{'portfolio-id'} = 'BST';
===
Can it be done? Any help will be appreciated.
Kind regards,
Harm Bandstra
Hi Harm
Yep, you found the right place to ask the question. I don't know the
answer off the top of my head and I'm in the middle of rebuilding my
PHP environment today so I'll take a look when I get it sorted. Sorry
about the slight delay. I'll get back to you shortly.
In the mean tim, if anyone else knows the answer feel free to jump
in:-)
Regards
Simon
Hi Harm

Sorry this took me a while to get to. Have just managed to get my dev
environment up on my new machine following the demise of my old one.
The reason that this is failing is that the Tuscany SDO implementation
that we rely on for SDO support doesn't recognize the "-" character as
a valid character in a name. I think that it should in as much that it
is a valid name character [1]. Can you raise a bug report on this and
I'll log it in Tuscany and make a change. I can make the change
locally on PECL in the first instance. If people have doubts about
this then let me know.

Thanks

Simon
Paul Scott
2007-11-14 12:48:42 UTC
Permalink
Post by simonslaws-gM/Ye1E23mwN+
I'll log it in Tuscany and make a change. I can make the change
locally on PECL in the first instance. If people have doubts about
this then let me know.
I have some serious doubts about that... Modifying to cater for
hyphenated names is asking for trouble - kind of like modifying SQL
standards to let people create reserved word field names...
simonslaws-gM/Ye1E23mwN+
2007-11-14 13:40:19 UTC
Permalink
Post by Paul Scott
Post by simonslaws-gM/Ye1E23mwN+
I'll log it in Tuscany and make a change. I can make the change
locally on PECL in the first instance. If people have doubts about
this then let me know.
I have some serious doubts about that... Modifying to cater for
hyphenated names is asking for trouble - kind of like modifying SQL
standards to let people create reserved word field names...
--Paul
All Email originating from UWC is covered by disclaimerhttp://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm
Hi Paul

My reference [1] should have been (http://www.w3.org/TR/REC-xml/#NT-
NameChar).
Post by Paul Scott
From this it looks to me like "-" can validly appear in the XML names,
but not the first character. I don't see anything in the SDO C++ spec
that describes the character set that forms property names in SDO
other than by implication through its discussion of XPath. There is a
danger here that looking in a spec for something that maybe excluded
is always problematic.

Are you suggesting that the "-" character should not appear in
property names? One view would be to rule it out because it causes
particular problems in PHP scripts. However that approach presents
problems for people what to use existing schema. While the object->my-
property syntax won't work you could expect the object['my-property']
or object->{'my-property'} to work.

Regards

Simon
Harm Bandstra
2007-11-14 14:34:22 UTC
Permalink
Hi Simon,

I filed a bug report here: http://pecl.php.net/bugs/bug.php?id=12443

Thank you for your help.

Regards,

Harm
Post by simonslaws-gM/Ye1E23mwN+
Post by Paul Scott
Post by simonslaws-gM/Ye1E23mwN+
I'll log it in Tuscany and make a change. I can make the change
locally on PECL in the first instance. If people have doubts about
this then let me know.
I have some serious doubts about that... Modifying to cater for
hyphenated names is asking for trouble - kind of like modifying SQL
standards to let people create reserved word field names...
--Paul
All Email originating from UWC is covered by disclaimerhttp://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm
Hi Paul
My reference [1] should have been (http://www.w3.org/TR/REC-xml/#NT-
NameChar).
Post by Paul Scott
From this it looks to me like "-" can validly appear in the XML names,
but not the first character. I don't see anything in the SDO C++ spec
that describes the character set that forms property names in SDO
other than by implication through its discussion of XPath. There is a
danger here that looking in a spec for something that maybe excluded
is always problematic.
Are you suggesting that the "-" character should not appear in
property names? One view would be to rule it out because it causes
particular problems in PHP scripts. However that approach presents
problems for people what to use existing schema. While the object->my-
property syntax won't work you could expect the object['my-property']
or object->{'my-property'} to work.
Regards
Simon
Caroline Maynard
2007-11-16 16:50:45 UTC
Permalink
Post by Paul Scott
Post by simonslaws-gM/Ye1E23mwN+
I'll log it in Tuscany and make a change. I can make the change
locally on PECL in the first instance. If people have doubts about
this then let me know.
I have some serious doubts about that... Modifying to cater for
hyphenated names is asking for trouble - kind of like modifying SQL
standards to let people create reserved word field names...
Paul, not sure where you're coming from here - I think this really
should work. There's no issue from the PHP point of view; this stuff is
documented under the "Variable variables" section of the manual
(http://php.net/manual/en/language.variables.variable.php), and the syntax

$my_object->{'weird-characters-here'} = "some text";

is perfectly respectable. And Simon has pointed us at the relevant
section of the XML spec (http://www.w3.org/TR/REC-xml/#NT-NameChar).
It's just a shame that Tuscany is barfing on it at present (I think it's
Tuscany rather than libxml, as borne out but Harm's successful use of
this syntax with simplexml).

Can you elaborate your doubts a bit more?
Paul Scott
2007-11-16 18:07:02 UTC
Permalink
Post by Caroline Maynard
Paul, not sure where you're coming from here - I think this really
should work. There's no issue from the PHP point of view; this stuff is
documented under the "Variable variables" section of the manual
(http://php.net/manual/en/language.variables.variable.php), and the syntax
$my_object->{'weird-characters-here'} = "some text";
is perfectly respectable. And Simon has pointed us at the relevant
I think that the spirit of my original post has kind of been lost now.
All that I am saying is that just because it *can* be done, does not
necessarily mean that it *should* be done.

At best, OP's case is a fringe case, and *probably* will cause more harm
than good in his application further down the line. If those cases are
not allowed (like Tuscanny) then, it is easier for OP to change one
variable now, than have a huge broken debugging nightmare later on. I
drew the example of SQL99 standards as I am well aware of the alarming
rate at which junior developers name date fields `date` in MySQL for
instance - perfectly legal according to MySQL, but a recipe for disaster
later on.
simonslaws-gM/Ye1E23mwN+
2007-11-16 18:18:43 UTC
Permalink
Post by Paul Scott
Post by Caroline Maynard
Paul, not sure where you're coming from here - I think this really
should work. There's no issue from the PHP point of view; this stuff is
documented under the "Variable variables" section of the manual
(http://php.net/manual/en/language.variables.variable.php), and the syntax
$my_object->{'weird-characters-here'} = "some text";
is perfectly respectable. And Simon has pointed us at the relevant
I think that the spirit of my original post has kind of been lost now.
All that I am saying is that just because it *can* be done, does not
necessarily mean that it *should* be done.
At best, OP's case is a fringe case, and *probably* will cause more harm
than good in his application further down the line. If those cases are
not allowed (like Tuscanny) then, it is easier for OP to change one
variable now, than have a huge broken debugging nightmare later on. I
drew the example of SQL99 standards as I am well aware of the alarming
rate at which junior developers name date fields `date` in MySQL for
instance - perfectly legal according to MySQL, but a recipe for disaster
later on.
--Paul
All Email originating from UWC is covered by disclaimerhttp://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm
I do see what you're saying Paul and we do have to be careful in cases
like these. I think if we were stepping outside of the various
specifications we would be on very dodgy ground. It's a balance
between supporting the schema that people already have (they most
likely use our technology if they have to change their schema to use
it) and not making it too easy for people to store up problems for
themselves as you say. Now we have a bug report for this I'll raise
one in Tuscany and see what the SDO community say. They may come back
with the same concerns that you have.

Regards

Simon
Caroline Maynard
2007-11-22 14:21:55 UTC
Permalink
Post by simonslaws-gM/Ye1E23mwN+
I do see what you're saying Paul and we do have to be careful in cases
like these. I think if we were stepping outside of the various
specifications we would be on very dodgy ground. It's a balance
between supporting the schema that people already have (they most
likely use our technology if they have to change their schema to use
they most likely >won't< use our technology .. ?
Post by simonslaws-gM/Ye1E23mwN+
it) and not making it too easy for people to store up problems for
themselves as you say. Now we have a bug report for this I'll raise
one in Tuscany and see what the SDO community say. They may come back
with the same concerns that you have.
The OP has some xml which validates against a schema, and which the XML
DAS consumes without a murmur but then Tuscany throws a confusing
exception when he tries to reference an element using valid PHP syntax,
which works for simplexml, dom and so on. This doesn't seem good enough
to me, and if we can't do any more because of Tuscany limitations, we
should at least provide an explanatory message documenting the
restriction - fortunately he worked out the cause of the problem for
himself.

I raised this on the Tuscany list
(http://thread.gmane.org/gmane.comp.apache.webservices.tuscany.devel/25795),
and Pete is having a think about the implications.
Caroline Maynard
2007-12-04 14:53:54 UTC
Permalink
Post by Caroline Maynard
I raised this on the Tuscany list
(http://thread.gmane.org/gmane.comp.apache.webservices.tuscany.devel/25795),
and Pete is having a think about the implications.
Tuscany have accepted my patch, so I've now checked it into our FULMAR
branch, and it will be in the next release.

Loading...