🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.xml
Article #95

delphi 2007 xml data binding. problems with namespaces.

#95
From: 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
Technical Details
Message-ID: <7440bfdd-e623-424b-b17e-22eb1deb6c63@r37g2000prr.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!r37g2000prr.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f5d9b,f56f75065fb2d9ab,start
X-Google-Attributes: gidf5d9b,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!r37g2000prr.googlegroups.com!not-for-mail
From: fabrizioverdesca@gmail.com
Newsgroups: borland.public.delphi.xml
Subject: delphi 2007 xml data binding. problems with namespaces.
Date: Mon, 2 Feb 2009 06:54:02 -0800 (PST)
Organization: http://groups.google.com
Lines: 169
Message-ID: <7440bfdd-e623-424b-b17e-22eb1deb6c63@r37g2000prr.googlegroups.com>
NNTP-Posting-Host: 62.123.231.39
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1233586442 20001 127.0.0.1 (2 Feb 2009 14:54:02 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 2 Feb 2009 14:54:02 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: r37g2000prr.googlegroups.com; posting-host=62.123.231.39; 
 posting-account=D-l7lQoAAADq14YOdhEZqvj7U06Oynr2
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.0.5) 
 Gecko/2008120122 Firefox/3.0.5,gzip(gfe),gzip(gfe)