RE: FW: [xml] libxml2 support for xml schema data types


-----Original Message-----
From: Milan Andric [mailto:andricm cs pdx edu] 


Many thanks for the reply - this is info I've been looking for.
I'm a beginner in X Schema, trying to find a way to describe 
a function
parameters in a way that would be satisfying for both Win/Linux.

Suppose there is a function foo(int i, char *j)

And call to function is like:

Foo(1, "hello")

I've thought of something like:

<Function Name=foo>
      <Param ### cross platform type info comes  here ###>1</Param>
      <Param Type="string">hello</Param>
</Function >

I'm trying to find a way to describe all my function params 
in a way that
is cross portable, and that would be understood by XML parsers on both
Windows and Linux.

Then, when above XML is programmatically (via DOM) parsed by 
XML parser,
it needs to be able to figure out actual param type, such 
that first param
is of type int, and assign such to int variable in program, that the
second param is of type string and make assigment to a 
variable in code,

So far I've been able to acomplish above with MSXML, but, as 
you've noted,
these are proprietary MS XML data types, and they wouldn't 
work for cross
platform purposes.

I'm wondering if there is a way to describe above params in such way -
what do you think?


The xsi:type attribute is intended for such purposes (e.g. used heavily

A schema could look like:

<?xml version="1.0"?>
<xs:schema xmlns:xs="";

  <xs:simpleType name="myIntType">
    <xs:restriction base="xs:int">
      <xs:maxInclusive value="10"/>

  <xs:element name="param" type="xs:anySimpleType"/>      

  <xs:element name="function">
      <xs:sequence maxOccurs="unbounded">
        <xs:element ref="m:param"/>

And the corresponding instance:

<?xml version="1.0"?>
<m:function xmlns:m="urn:test:milan"
  xsi:schemaLocation="urn:test:milan milan-functions.xsd"

  <m:param xsi:type="xs:string">value-1</m:param>
  <m:param xsi:type="m:myIntType">10</m:param>


I recommend using the following mailing lists for general W3C XML Schema
questions (i.e., non Libxml2 related):

xml-dev lists xml org or xmlschema-dev w3 org 

... or reading some tutorials:

... or reading book about W3C XML Schema.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]