[xsd-users] String length

David Kelvin dktemp at hotmail.co.uk
Sun Oct 26 08:20:41 EDT 2008


Hi,
 
I am testing the code produced with XSD and using Expat as the parser.  I have an element tattribute defined in the schema with the following restriction:
 
<xs:simpleType name="characterType">  <xs:restriction base="xs:string">    <xs:length value="1" />  </xs:restriction></xs:simpleType>
 
In the following routine, I had checked the length to verify it is only 1 but it isn't always - it seems to depend on the character:
 
std::string characterType_pimpl::
post_characterType ()
{
const ::std::string& v (post_string ());
/*
<xs:restriction base="xs:string">
<xs:length value="1" />
</xs:restriction>
*/
std::cout << "length: " << v.length() << std::endl;
std::cout << "character: " << v.c_str() << std::endl;
return v;
}
 
For example, if the character in the XML file is a normal letter, digit or symbol, then it the length is 1.
 
However, we quite often use the character '»' ("0xbb" or Alt + 0187) and this returns the length of 2 and v.c_str() is "0xc2bb", although when the output is redirected to a text file (UTF-8), only the single character "»" appears.  If left to print to the screen, it is a different combination.
 
It looks like a char/wchar_t problem.
 
Thanks
 
David
 
_________________________________________________________________
Win an Xbox 360 or £200 Top Shop Vouchers 
http://clk.atdmt.com/GBL/go/115454062/direct/01/


More information about the xsd-users mailing list