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 Pascal Ledru <Pa...@Sun.COM> on 2004/01/21 22:06:34 UTC

Scheme question - attribute + text value

I havr hard time figure out how to handle the case with both an 
attribute and data such as:

<VALUE ID="release">abc</VALUE>

My XML file is:

<?xml version="1.0"?>
<HOST ID="host:boblu10.central.sun.com">
  <INFO>
    <VALUE ID="release">abc</VALUE>
    <VALUE ID="model2">MODEL</VALUE>
    <VALUE ID="mgmtLevel">D</VALUE>
    <VALUE ID="class">host</VALUE>
    <VALUE ID="bitMode">64</VALUE>
    <VALUE ID="hostid">80fce5ce</VALUE>
    <VALUE ID="model">MODEL2</VALUE>
  </INFO>

</HOST>

and the xsd file is:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                                        
                  >

  <xs:element name="HOST">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="INFO" type="INFO"/>
    </xs:sequence>
    <xs:attribute name="ID" type="xs:string"/>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="INFO">
    <xs:sequence>
    <xs:element name="VALUE" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
      <xs:simpleContent>
            <xs:extension base="xs:string">
        <xs:attribute name="ID" type="xs:string" use="required"/>
            </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
  </xs:complexType>

</xs:schema>


and program is:

    HOSTDocument hostDoc = HOSTDocument.Factory.parse(po);

    HOST host = hostDoc.getHOST();

    INFO info = host.getINFO();
    VALUE[] values = info.getVALUEArray();

    for (int j = 0; j < values.length; j++) {
      //System.out.println("VALUE: " + values[j].getID() + " " + 
values[j].getValue() );
    System.out.println("VALUE: " + values[j].getID() + " " + values[j]);
    }



Somehow, I would like to have a method in the VALUE class such as 
getValue to pick up the text data (such as 'abc' in my example). I need 
to be able to specify the name of the method for the simpleContent or 
extension?

This is probably a trivial question, but so far I have not been able to 
figure it out.

Any help would be really appreciated!

Thanks,

Pascal

 


- ---------------------------------------------------------------------
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: Scheme question - attribute + text value

Posted by Pascal Ledru <Pa...@Sun.COM>.
Never mind. Found it:

values[j].getStringValue()

will get it!




Pascal Ledru wrote:

> I havr hard time figure out how to handle the case with both an 
> attribute and data such as:
>
> <VALUE ID="release">abc</VALUE>
>
> My XML file is:
>
> <?xml version="1.0"?>
> <HOST ID="host:boblu10.central.sun.com">
>  <INFO>
>    <VALUE ID="release">abc</VALUE>
>    <VALUE ID="model2">MODEL</VALUE>
>    <VALUE ID="mgmtLevel">D</VALUE>
>    <VALUE ID="class">host</VALUE>
>    <VALUE ID="bitMode">64</VALUE>
>    <VALUE ID="hostid">80fce5ce</VALUE>
>    <VALUE ID="model">MODEL2</VALUE>
>  </INFO>
>
> </HOST>
>
> and the xsd file is:
>
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>                                                                        
>                  >
>
>  <xs:element name="HOST">
>    <xs:complexType>
>    <xs:sequence>
>    <xs:element name="INFO" type="INFO"/>
>    </xs:sequence>
>    <xs:attribute name="ID" type="xs:string"/>
>    </xs:complexType>
>  </xs:element>
>
>  <xs:complexType name="INFO">
>    <xs:sequence>
>    <xs:element name="VALUE" minOccurs="0" maxOccurs="unbounded">
>    <xs:complexType>
>      <xs:simpleContent>
>            <xs:extension base="xs:string">
>        <xs:attribute name="ID" type="xs:string" use="required"/>
>            </xs:extension>
>      </xs:simpleContent>
>    </xs:complexType>
>    </xs:element>
>    </xs:sequence>
>  </xs:complexType>
>
> </xs:schema>
>
>
> and program is:
>
>    HOSTDocument hostDoc = HOSTDocument.Factory.parse(po);
>
>    HOST host = hostDoc.getHOST();
>
>    INFO info = host.getINFO();
>    VALUE[] values = info.getVALUEArray();
>
>    for (int j = 0; j < values.length; j++) {
>      //System.out.println("VALUE: " + values[j].getID() + " " + 
> values[j].getValue() );
>    System.out.println("VALUE: " + values[j].getID() + " " + values[j]);
>    }
>
>
>
> Somehow, I would like to have a method in the VALUE class such as 
> getValue to pick up the text data (such as 'abc' in my example). I 
> need to be able to specify the name of the method for the 
> simpleContent or extension?
>
> This is probably a trivial question, but so far I have not been able 
> to figure it out.
>
> Any help would be really appreciated!
>
> Thanks,
>
> Pascal
>
>
>



- ---------------------------------------------------------------------
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: Scheme question - attribute + text value

Posted by Pascal Ledru <Pa...@Sun.COM>.
Never mind. Found it:

values[j].getStringValue()

will get it!




Pascal Ledru wrote:

> I havr hard time figure out how to handle the case with both an 
> attribute and data such as:
>
> <VALUE ID="release">abc</VALUE>
>
> My XML file is:
>
> <?xml version="1.0"?>
> <HOST ID="host:boblu10.central.sun.com">
>  <INFO>
>    <VALUE ID="release">abc</VALUE>
>    <VALUE ID="model2">MODEL</VALUE>
>    <VALUE ID="mgmtLevel">D</VALUE>
>    <VALUE ID="class">host</VALUE>
>    <VALUE ID="bitMode">64</VALUE>
>    <VALUE ID="hostid">80fce5ce</VALUE>
>    <VALUE ID="model">MODEL2</VALUE>
>  </INFO>
>
> </HOST>
>
> and the xsd file is:
>
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>                                                                        
>                  >
>
>  <xs:element name="HOST">
>    <xs:complexType>
>    <xs:sequence>
>    <xs:element name="INFO" type="INFO"/>
>    </xs:sequence>
>    <xs:attribute name="ID" type="xs:string"/>
>    </xs:complexType>
>  </xs:element>
>
>  <xs:complexType name="INFO">
>    <xs:sequence>
>    <xs:element name="VALUE" minOccurs="0" maxOccurs="unbounded">
>    <xs:complexType>
>      <xs:simpleContent>
>            <xs:extension base="xs:string">
>        <xs:attribute name="ID" type="xs:string" use="required"/>
>            </xs:extension>
>      </xs:simpleContent>
>    </xs:complexType>
>    </xs:element>
>    </xs:sequence>
>  </xs:complexType>
>
> </xs:schema>
>
>
> and program is:
>
>    HOSTDocument hostDoc = HOSTDocument.Factory.parse(po);
>
>    HOST host = hostDoc.getHOST();
>
>    INFO info = host.getINFO();
>    VALUE[] values = info.getVALUEArray();
>
>    for (int j = 0; j < values.length; j++) {
>      //System.out.println("VALUE: " + values[j].getID() + " " + 
> values[j].getValue() );
>    System.out.println("VALUE: " + values[j].getID() + " " + values[j]);
>    }
>
>
>
> Somehow, I would like to have a method in the VALUE class such as 
> getValue to pick up the text data (such as 'abc' in my example). I 
> need to be able to specify the name of the method for the 
> simpleContent or extension?
>
> This is probably a trivial question, but so far I have not been able 
> to figure it out.
>
> Any help would be really appreciated!
>
> Thanks,
>
> Pascal
>
>
>



- ---------------------------------------------------------------------
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/