Hello,

I'm using XML::Compile:schema to generate xml from a hash using a xsd as a 
kinda template. All is fine until I want use that same xsd to add in the xml so 
that it can be later validated against the same xsd. I begin to explain what I 
did.

In my "variables.xsd" I've got:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
xmlns:xs="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://www.example.org/esquemas/application"; 
xmlns="http://www.example.org/esquemas/application";>
  <xs:element name="application">
    <xs:complexType>
      <xs:sequence>
        <xs:element type="xs:string" name="prdocc"/>
        <xs:element type="xs:string" name="sysid"/>
        <xs:element type="xs:string" name="login"/>
        <xs:element name="variables">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="variable" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="name"/>
                    <xs:element type="xs:string" name="value"/>
                    <xs:element type="xs:string" name="description"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

In my code I have this:

my $xsd = $catalogData . 'popeiIndus.xsd';
my $schema = XML::Compile::Schema->new($xsd);
$schema->addSchemaDirs($catalogData);
$schema->importDefinitions('popeiIndus.xsd');
my $type = pack_type 'http://www.example.org/esquemas/application', 
'application';
$schema->printIndex;
my $doc    = XML::LibXML::Document->new('1.0', 'UTF-8');
my $write  = $schema->compile(WRITER => $type, );
my $xml    = $write->($doc, \%application);
$doc->setDocumentElement($xml);
print $doc->toString(1);


As a result I've got this:

<?xml version="1.0" encoding="UTF-8"?>
<x0:application xmlns:x0="http://www.example.org/esquemas/application";>
  <x0:prdocc>XXXXX</x0:prdocc>
  <x0:sysid>xxxxXXX</x0:sysid>
  <x0:login>xxxxxx</x0:login>
  <x0:variables>
    <x0:variable>
      <x0:name>XXXXXX</x0:name>
      <x0:value>/xxx/xxxx/xxx/xxxx</x0:value>
      <x0:description>Xxxxxxx Xxxxxxxxxx Xxxxxxx</x0:description>
    </x0:variable>
.................
  </x0:variables>
</x0:application>

But what I'd like to obtain is something like this :


<?xml version="1.0" encoding=" UTF-8"?>
< application xmlns=' http://www.example.org/esquemas/application'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="variables.xsd">
  < prdocc>XXXXX</x0:prdocc>
  < sysid>xxxxXXX</x0:sysid>
  < login>xxxxxx</x0:login>
  < variables>
    < variable>
      < name>XXXXXX</x0:name>
      < value>/xxx/xxxx/xxx/xxxx</x0:value>
      < description>Xxxxxxx Xxxxxxxxxx Xxxxxxx</x0:description>
    </ variable>
.................
  </variables>
</application>


What am I doing wrong, I'm been searching how to do that and I'm quite lost. 
Sorry if this is too obvious or it is explained somewhere but I didn't found it.
Many thanks.

Un saludo.

José Ramón González Martínez
DRHQ/DSIN/SIFA/ISIN
SIVSA for PSA Peugeot Citroën - Vigo

mailto:[email protected]

[Descripción: sivsa]
SIVSA, Soluciones Informáticas S.A.

<<inline: image001.jpg>>

_______________________________________________
Xml-compile mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile

Reply via email to