Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Schema defining number of decimal places

Status
Not open for further replies.

dwichmann

IS-IT--Management
Jul 15, 2005
42
GB
all, i have written the following schema and want to use it to pass the quote value to 2 decimal places. I belive i have the correct code but it doesnt seem to change the number of decimal places at all. It seems that it is ignoring the fractiondigits value. Please help its driving me mad

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs=" name="Wickens">
<xs:complexType>
<xs:sequence>
<xs:element name="test1" type="xs:string"/>
<xs:element name="quotevalue">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="Wickens" type="xs:string" use="required"/>
</xs:complexType>
</xs:element></xs:schema>
 
Maybe the clue lies here.
>... but it doesnt seem to change the number of decimal places at all.
Having a correct schema will not "[blue]change[/blue] the number of decimal place at all", valid or invalid. To change the invalid to valid number of decimal point is beyond the purpose of the schema.
 
apologies i wasnt aware of that, not sure if your able to help me. I wrote the schema to allow me to export entries into an excel spreadsheet in xml format. I have formatted the excel spreadsheet but when i export in xml it gives me full values where i would like them rounded to 2 decimal places. Is it possible to change this?
 
I don't think the use of schema in the office can be extended to casting the datatype to the desired type. (I am not office2003 user, so I may be wrong.) It's use as data map through gui can be very functional. It can be instructed to validate during the export. If data is invalid, it just issue a warning, if so instructed, but I am not aware if it would change the data to the desired type.

Check out this hand-on guide article.
In particular, it mentioned this.
Note that the XML data file is created regardless of whether schema validation fails or not.[unquote]

Since you have all the tools available, you should be in the position to verify this. (Change the number to 3 digits and inspect the exported xml document source file.) I would be interested to know the outcome and prove my reading of it wrong.

The way to make physical change of the number can rather be done by passing it through a xslt stylesheet where you can use the built-in functions on number. (Or fix it in the spreedsheet.) It still, however, needs to hard-script the where and how to change.

To make thing automatically happen by provisioning a schema side-by-side of the xml document through an application is in principle possible and even desirable. But making schema-aware application is expensive. I am not aware of any in the domain of free and open source. It will come one-day I think.
 
I am a bit confused by your description of your process. However, it seems like you have an XML-generating process which creates information, which you then wish to pass to Excel, to be displayed as a spreadsheet.

If this is indeed the case, then you need to transform the created XML (using XSLT) to make use of the application-specific SpreadsheetML dialect. In particular, there is a styles section of the document with this structure:
Code:
<Styles> 
   <Style ss:ID="Default" ss:Name="Normal"> 
      <Alignment ss:Vertical="Bottom"/> 
      <Borders/> 
      <Font/> 
      <Interior/> 
      <NumberFormat/> 
      <Protection/> 
   </Style> 
</Styles>
You can define several styles, as needed, Then, for the data cells that require rounding, you 'apply' the style by the ID (using the StyleID attribute).

The Microsoft web site has a lot of information, including the reference schemas for Office 2003 which can be found by Googling for [google]office 2003 reference schemas[/google]. Download the schemas. After you install them, you can find a help file (.chm) that does a reasonable job of explaining SpreadsheetML.

So, you can create the data in such a way that you control the way Excel displays the data.

Is this helpful? [ponder]

Tom Morrison
 
thank for the help both, i will give it a go. i am using the schema to export the data out of excel and into a different application.I have tried formatting in the data in excel before exporting it but it doesnt seem to make any difference. i will keep you posted, thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top