[xsd-users] Convert a type, created by the xsd-tool, to DOMElement type, defined in xerces

Lickert, Dominik (LEN, DivHG) DLickert at testo.de
Mon Dec 5 08:56:07 EST 2011


Hi Boris,

My problem is, that I want to read out the content / NodeValue of an element, but there is no function in the generated code for that.

The element I mean is the "Text" element. I printed the three types, where it occurs in the xsd file and a part of the xml file:
(The Shape_Type bases on the ShapeSheet_Type)

            <xsd:complexType name="ShapeSheet_Type">
                        <xsd:choice minOccurs="0" maxOccurs="unbounded">
==>                              <xsd:element name="Text" type="Text_Type" minOccurs="0"/>             <==
                                   <xsd:element name="XForm" type="XForm_Type" minOccurs="0"/>
                                   <xsd:element name="Line" type="Line_Type" minOccurs="0"/>
                                   <xsd:element name="Fill" type="Fill_Type" minOccurs="0"/>
                                   <xsd:element name="XForm1D" type="XForm1D_Type" minOccurs="0"/>
                                   <xsd:element name="Event" type="Event_Type" minOccurs="0"/>

                                   ...

                                   <xsd:element name="Data3" type="Data3_Type" minOccurs="0"/>
                                   <xsd:element name="ForeignData" type="ForeignData_Type" minOccurs="0"/>
                                   <xsd:any namespace="##other" processContents="lax"/>
                        </xsd:choice>
                        <xsd:attribute name="LineStyle" type="xsd:unsignedLong"/>
                        <xsd:attribute name="FillStyle" type="xsd:unsignedLong"/>
                        <xsd:attribute name="TextStyle" type="xsd:unsignedLong"/>
                        <xsd:anyAttribute namespace="##other" processContents="lax"/>
            </xsd:complexType>


            <xsd:complexType name="Text_Type" mixed="true">
                        <xsd:complexContent mixed="true">
                                   <xsd:extension base="TextCell_Type"/>
                        </xsd:complexContent>
            </xsd:complexType>


            <xsd:complexType name="TextCell_Type" mixed="true">
                        <xsd:choice minOccurs="0" maxOccurs="unbounded">
                                   <xsd:element name="cp" type="cp_Type" minOccurs="0" maxOccurs="unbounded"/>
                                   <xsd:element name="pp" type="pp_Type" minOccurs="0" maxOccurs="unbounded"/>
                                   <xsd:element name="tp" type="tp_Type" minOccurs="0" maxOccurs="unbounded"/>
                                   <xsd:element name="fld" type="fld_Type" minOccurs="0" maxOccurs="unbounded"/>
                        </xsd:choice>
            </xsd:complexType>

Short part of the XML file:

- <Shapes>
- <Shape ID="1" NameU="Process" Name="Prozess" Type="Shape" Master="2">
+ <Char IX="0">
+ <vx:Char IX="0" xmlns:vx="http://schemas.microsoft.com/visio/2006/extension">
+ <XForm>
+ <Event>
+ <vx:Event xmlns:vx="http://schemas.microsoft.com/visio/2006/extension">

...

- <Text>
<cp IX="0" />
Task
</Text>
</Shape>
</Shapes>

In the xsd file, it isn't defined, that the "Text" element can have an content. I look up in the hello example and in the wildcard example. But the two methods of this projects don't work. The wildcard project convert a any_iterator in a DOMElement. Is this also possible with a no-any_type? My compiler don't accept this.

I tried it with the following code, but the "Text" element isn't a any_type, only a few any_type occurring here.

            core:: Shape_Type::any_sequence& AnySeqShape (ShapeT->any());

            for(core:: Shape_Type::any_iterator AnyIt (AnySeqShape.begin()); AnyIt != AnySeqShape.end(); AnyIt++)
            {
                        DOMElement& e (*AnyIt);
                        string name (xml::transcode<char> (e.getLocalName ()));
                        cout << "- " << name << endl;
                        XMLString::release(&name);
            }

So I tried it with the following code, but the compiler don't accept the second line of the for-loop. Only the first one works, but with that conversion, I can't access to the content of the element.

            core::Shape_Type::Text_sequence& TxtSeq (&ShapeT->Text());

            for(core::Shape_Type::Text_iterator TxtIt (TxtSeq.begin()); TxtIt != TxtSeq.end(); TxtIt++)
            {
                        core::Shape_Type::Text_type* TxtTy = dynamic_cast<core::Shape_Type::Text_type*> (&*TxtIt);

                        DOMElement& DomElem (*TxtIt);
            }

Is this actually the right way, or Is there another way to read out the content of an element in a string or char variable?

Best Regards
Dominik

Testo AG, Lenzkirch, Commercial Register Freiburg 320456 - Board of Directors: Burkart Knospe (CEO), Lothar Walleser, Martin Winkle, Dr. Jörk Hebenstreit- Supervisory board: Anne-Kathrin Deutrich (Chairperson), Klaus Fritzsching, Hartmut Herrlinger, Testo AG, Testo-Strasse 1, 79853 Lenzkirch, Germany


More information about the xsd-users mailing list