php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56712 Impossible to insert element value wich also has attributes
Submitted: 2005-12-08 15:00 UTC Modified: 2006-10-30 06:31 UTC
From: bjori@php.net Assigned:
Status: Not a bug Package: SCA_SDO (PECL)
PHP Version: 5_1 CVS-2005-12-08 OS: FreeBSD6.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 - 25 = ?
Subscribe to this entry?

 
 [2005-12-08 15:00 UTC] bjori@php.net
Description:
------------
I can't seem to find a way to apply a value to element wich also has attributes.

Reproduce code:
---------------
<?php
    $xsd = <<< EOT
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://fooSchema" elementFormDefault="qualified"
        attributeFormDefault="unqualified"
        xmlns:foo="http://fooSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="root">
        <xs:complexType>
            <xs:choice>
                <xs:element name="element" type="foo:elementType" />
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="elementType" mixed="true">
        <xs:attribute name="attribute" type="xs:string" />
    </xs:complexType>
</xs:schema>
EOT;

    $file = tempnam("/tmp", "sdo");
    file_put_contents($file, $xsd);
    $xmldas = SDO_DAS_XML::create($file);
    unlink($file);
    $root = $xmldas->createDataObject("http://fooSchema", "root");

    /*$root->element = "value";
    *  Fatal error: SDO_DataObject:681: cannot cast stdClass to SDO_DataObjectImpl in ...
    *  So I guess I need to create the element...
    */
    $element = $root->createDataObject("element");
    $element->attribute = "value";
    // How in gods name do I insert a value to the element itself - not the attributes now? :)

    print new SDO_Model_ReflectionDataObject($element);
?>


Expected result:
----------------
$root->element = "value";
// <element>value</element>
$element = $root->createDataObject("element");
$element->attribute = "attributeValue";
//<element attribute="attributeValue">value</element>

Actual result:
--------------
Impossible afaict

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-09 04:59 UTC] charters at uk dot ibm dot com
Sorry, but your problem does not imply a bug in PECL itself.  For a
list of more appropriate places to ask for help using PECL, please
visit http://pecl.php.net/support/ as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PECL.

Mixed="true" results in SDO creating a "sequenced type".
One of the things a sequenced type supports is unstructured
text which, given the element in the provided schema 
doesn't really have a type, is what will go into the 
element value. 

To modify a data object which is a sequenced type, you
need to get the data object's sequence interface.  I've updated
the sample to show this.

For more info on sequenced types, see the section on 
"Working with Sequenced Data Object" in the 
docs (http://docs.php.net/en/ref.sdo.html).

Updated Sample
--------------

<?php
    $xsd = <<< EOT
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://fooSchema"
elementFormDefault="qualified"
        attributeFormDefault="unqualified"
        xmlns:foo="http://fooSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="root">
        <xs:complexType>
            <xs:choice>
                <xs:element name="element" type="foo:elementType" />
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="elementType" mixed="true">
        <xs:attribute name="attribute" type="xs:string" />
    </xs:complexType>
</xs:schema>
EOT;

    $file = tempnam("/tmp", "sdo");
    file_put_contents($file, $xsd);
    $xmldas = SDO_DAS_XML::create($file);
    unlink($file);
    $root = $xmldas->createDataObject("http://fooSchema", "root");

    /*$root->element = "value";
    *  Fatal error: SDO_DataObject:681: cannot cast stdClass to
SDO_DataObjectImpl in ...
    *  So I guess I need to create the element...
    */
    $element = $root->createDataObject("element");
    $element->attribute = "value";
    // How in gods name do I insert a value to the element 
    // itself - not the attributes now? :)

    // mixed="true" results in SDO creating a "sequenced type".
    // One of the things a sequenced type supports is unstructured
    // text.  The following gets the sequence for the element and
    // appends some unstructured text.
    $seq = $element->getSequence();
    $seq[] = "Hello";
    
    echo htmlspecialchars($xmldas->saveDataObjectToString($root, "http://fooSchema", "root"));
    
    /* Outputs
    <?xml version="1.0" encoding="UTF-8"?> 
    <root xmlns="http://fooSchema" xsi:type="root" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <element attribute="value">Hello</element>
    </root>
    */
    
    print new SDO_Model_ReflectionDataObject($element);
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 21:01:29 2024 UTC