🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.xml
1 messages
1 total messages Started by fabrizioverdesca Mon, 02 Feb 2009 14:54
delphi 2007 xml data binding. problems with namespaces.
#95
Author: fabrizioverdesca
Date: Mon, 02 Feb 2009 14:54
169 lines
6748 bytes
I tried to import an xml schema with XML Data Bindind (Delphi 2007),
but i have a problem with namespaces.
The namespace is written before every element, and not only before the
root element.

I obtain these code:

<?xml version="1.0"?>
<ns2:CodeList
xmlns:ns2="http://docs.oasis-open.org/codelist/ns/genericode/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://docs.oasis-open.org/codelist/ns/genericode/
1.0/
http://docs.oasis-open.org/codelist/genericode/xsd/genericode.xsd">
  <ns2:Identification>
    <ns2:ShortName>NT1</ns2:ShortName>
    <ns2:LongName xml:lang="it">Tipo ordine</ns2:LongName>
    <ns2:LongName xml:lang="en">Order type</ns2:LongName>
    <ns2:Version>2008-1</ns2:Version>

<ns2:CanonicalUri>urn:x-moda-ml:specification:documents:decoding-
tables:xml:NT1</ns2:CanonicalUri>

<ns2:CanonicalVersionUri>urn:x-moda-
ml:specification:documents:decoding-tables:xml:NT1:2008-1</
ns2:CanonicalVersionUri>

<ns2:LocationUri>http://www.moda-ml.net/moda-ml/repository/codelist/
v2008-1/gc_NT1.xml</ns2:LocationUri>
    <ns2:Agency>
      <ns2:LongName>Organizzazione</ns2:LongName>
    </ns2:Agency>
  </ns2:Identification>
  <ns2:ColumnSet>
    <ns2:Column Id="Code" Use="required">
      <ns2:ShortName>Code</ns2:ShortName>
      <ns2:Data Type="string"/>
    </ns2:Column>
    <ns2:Column Id="Description" Use="optional">
      <ns2:ShortName xml:lang="en">Description</ns2:ShortName>
      <ns2:Data Type="string"/>
    </ns2:Column>
    <ns2:Column Id="Descrizione" Use="optional">
      <ns2:ShortName xml:lang="it">Descrizione</ns2:ShortName>
      <ns2:Data Type="string"/>
    </ns2:Column>
    <ns2:Key Id="CodeKey">
      <ns2:ShortName>CodeKey</ns2:ShortName>
      <ns2:ColumnRef Ref="Code"/>
    </ns2:Key>
  </ns2:ColumnSet>
  <ns2:SimpleCodeList>
    <ns2:Row>
      <ns2:Value ColumnRef="Code">
        <ns2:SimpleValue>A</ns2:SimpleValue>
      </ns2:Value>
      <ns2:Value ColumnRef="Description">
        <ns2:SimpleValue>blanket</ns2:SimpleValue>
      </ns2:Value>
      <ns2:Value ColumnRef="Descrizione">
        <ns2:SimpleValue>aperto</ns2:SimpleValue>
      </ns2:Value>
    </ns2:Row>
  </ns2:SimpleCodeList>
</ns2:CodeList>


instead of this one:

<?xml version="1.0"?>
<ns2:CodeList xmlns:ns2="http://docs.oasis-open.org/codelist/ns/
genericode/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://docs.oasis-open.org/codelist/ns/genericode/
1.0/ http://docs.oasis-open.org/codelist/genericode/xsd/genericode.xsd">
  <Identification>
    <ShortName>NT1</ShortName>
    <LongName xml:lang="en">Order type</LongName>
        <LongName xml:lang="it">Tipo ordine</LongName>
    <Version>2008-1</Version>
    <CanonicalUri>urn:x-moda-ml:specification:documents:decoding-
tables:xml:NT1</CanonicalUri>
    <CanonicalVersionUri>urn:x-moda-
ml:specification:documents:decoding-tables:xml:NT1:2008-1</
CanonicalVersionUri>
    <LocationUri>http://www.moda-ml.net/moda-ml/repository/codelist/
v2008-1/gc_NT1.xml</LocationUri>
    <Agency>
      <LongName Identifier="Organizzazione"/>
    </Agency>
  </Identification>
  <ColumnSet>
    <Column Id="Code" Use="required">
		<ShortName>Code</ShortName>
      <Data Type="string"/>
    </Column>
    <Column Id="Description" Use="optional">
            <ShortName xml:lang="en">Description</ShortName>
            <Data Type="string"/>
        </Column>
        <Column Id="Descrizione" Use="optional">
            <ShortName xml:lang="it">Descrizione</ShortName>
            <Data Type="string"/>
        </Column>
    <Key Id="CodeKey">
      <ShortName xml:lang=""/>
      <ColumnRef Ref="Code"/>
    </Key>
  </ColumnSet>
  <SimpleCodeList>
    <Row>
      <Value ColumnRef="Code">
		  <SimpleValue>A</SimpleValue>
	</Value>
      <Value ColumnRef="Description">
		  <SimpleValue>blanket</SimpleValue>
	  </Value>
      <Value ColumnRef="Descrizione">
		  <SimpleValue>aperto</SimpleValue>
       </Value>
    </Row>
  </SimpleCodeList>
</ns2:CodeList>


So, in the first example, the ns2 label, the namespace, is written
before every element dependent from the root element. If i try to
validate this code using XML Spy, i get an error.

This is the function created by the wizard:

function NewCodeList: IXMLCodeListDocument;
begin
  Result := NewXMLDocument.GetDocBinding('CodeList',
TXMLCodeListDocument, TargetNamespace) as IXMLCodeListDocument;
end;

but in this way the namespace is omitted. i've re-written the
function:

function NewCodeList: IXMLCodeListDocument;
begin
  Result := NewXMLDocument.GetDocBinding('ns2:CodeList',
TXMLCodeListDocument, TargetNamespace) as IXMLCodeListDocument;
end;

With this new version i have the namespace

<ns2:CodeList
xmlns:ns2="http://docs.oasis-open.org/codelist/ns/genericode/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://docs.oasis-open.org/codelist/ns/genericode/
1.0/
http://docs.oasis-open.org/codelist/genericode/xsd/genericode.xsd">

but also the ns2 label reported before every element and not only
before the root, ex:
 <ns2:Identification>
    <ns2:ShortName>NT1</ns2:ShortName>
    <ns2:LongName xml:lang="it">Tipo ordine</ns2:LongName>

instead of:
 <Identification>
    <ShortName>NT1</ShortName>
    <LongName xml:lang="it">Tipo ordine</LongName>


Any suggestion will be very appreciated, thanks.

Fabrizio Verdesca, fabrizio@inteaonline.it
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads