У меня есть следующая схема XSD
http://release.niem.gov/niem/apco/2.1/apco.xsd, и
Я написал следующий скрипт на Perl (я новичок в Perl, и, вероятно, в конечном итоге я напишу его на C #):
#!/usr/bin/perl
use warnings;
use strict;
# use module
use XML::Simple;
use Data::Dumper;
my $data = XMLin('apco.xsd');
print Dumper($data);
for my $key1 (keys %$data) {
print "$key1\n";
for my $array_value (@{ $data->{$key1} }) {
for my $key2 (keys %$array_value) {
print "$key2 : $array_value->{$key2}\n";
}
}
}
Я получил следующий вывод:
$VAR1 = {
'xsd:import' => [
{
'namespace' => 'http://niem.gov/niem/structures/2.0',
'schemaLocation' => '../../structures/2.0/structures.xsd'
},
{
'namespace' => 'http://niem.gov/niem/appinfo/2.0',
'schemaLocation' => '../../appinfo/2.0/appinfo.xsd'
}
],
'version' => '1',
'xmlns:s' => 'http://niem.gov/niem/structures/2.0',
'targetNamespace' => 'http://niem.gov/niem/apco/2.1',
'xmlns:i' => 'http://niem.gov/niem/appinfo/2.0',
'xsd:simpleType' => {
'AlarmEventCategoryCodeSimpleType' => {
'xsd:restriction' => {
'base' => 'xsd:token',
'xsd:enumeration' => [
{
'value' => 'Medical',
'xsd:annotation' => {
'xsd:documentation' => 'Medical Alarm'
}
},
{
'value' => 'FIRE',
'xsd:annotation' => {
'xsd:documentation' => 'Fire'
}
},
{
'value' => 'Comm',
'xsd:annotation' => {
'xsd:documentation' => 'Communication Fail'
}
},
{
'value' => 'BURG',
'xsd:annotation' => {
'xsd:documentation' => 'Burglary'
}
},
{
'value' => 'Holdup',
'xsd:annotation' => {
'xsd:documentation' => 'Holdup / Duress'
}
}
]
},
'xsd:annotation' => {
'xsd:appinfo' => {
'i:Base' => {
'i:name' => 'Object',
'i:namespace' => 'http://niem.gov/niem/structures/2.0'
}
},
'xsd:documentation' => 'A data type for kinds of alarm events.'
}
},
'AlarmEventResponseActionCodeSimpleType' => {
'xsd:restriction' => {
'base' => 'xsd:token',
'xsd:enumeration' => [
{
'value' => 'respond',
'xsd:annotation' => {
'xsd:documentation' => 'respond'
}
},
{
'value' => 'notify',
'xsd:annotation' => {
'xsd:documentation' => 'notify'
}
}
]
},
'xsd:annotation' => {
'xsd:appinfo' => {
'i:Base' => {
'i:name' => 'Object',
'i:namespace' => 'http://niem.gov/niem/structures/2.0'
}
},
'xsd:documentation' => 'A data type for actions requested of an alarm event responder.'
}
},
'AlarmEventLocationCategoryCodeSimpleType' => {
'xsd:restriction' => {
'base' => 'xsd:token',
'xsd:enumeration' => [
{
'value' => 'commercial',
'xsd:annotation' => {
'xsd:documentation' => 'commercial'
}
},
{
'value' => 'residential',
'xsd:annotation' => {
'xsd:documentation' => 'residential'
}
}
]
},
'xsd:annotation' => {
'xsd:appinfo' => {
'i:Base' => {
'i:name' => 'Object',
'i:namespace' => 'http://niem.gov/niem/structures/2.0'
}
},
'xsd:documentation' => 'A data type for the kinds of location at which an alarm event occurs.'
}
}
},
'xmlns:apco' => 'http://niem.gov/niem/apco/2.1',
'xsd:annotation' => {
'xsd:appinfo' => {
'i:ConformantIndicator' => 'true'
},
'xsd:documentation' => 'Association of Public-Safety Communications Officials (APCO) - International, Inc.'
},
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
'xsd:complexType' => {
'AlarmEventCategoryCodeType' => {
'xsd:annotation' => {
'xsd:appinfo' => {
'i:Base' => {
'i:name' => 'Object',
'i:namespace' => 'http://niem.gov/niem/structures/2.0'
}
},
'xsd:documentation' => 'A data type for kinds of alarm events.'
},
'xsd:simpleContent' => {
'xsd:extension' => {
'base' => 'apco:AlarmEventCategoryCodeSimpleType',
'xsd:attributeGroup' => {
'ref' => 's:SimpleObjectAttributeGroup'
}
}
}
},
'AlarmEventResponseActionCodeType' => {
'xsd:annotation' => {
'xsd:appinfo' => {
'i:Base' => {
'i:name' => 'Object',
'i:namespace' => 'http://niem.gov/niem/structures/2.0'
}
},
'xsd:documentation' => 'A data type for actions requested of an alarm event responder.'
},
'xsd:simpleContent' => {
'xsd:extension' => {
'base' => 'apco:AlarmEventResponseActionCodeSimpleType',
'xsd:attributeGroup' => {
'ref' => 's:SimpleObjectAttributeGroup'
}
}
}
},
'AlarmEventLocationCategoryCodeType' => {
'xsd:annotation' => {
'xsd:appinfo' => {
'i:Base' => {
'i:name' => 'Object',
'i:namespace' => 'http://niem.gov/niem/structures/2.0'
}
},
'xsd:documentation' => 'A data type for the kinds of location at which an alarm event occurs.'
},
'xsd:simpleContent' => {
'xsd:extension' => {
'base' => 'apco:AlarmEventLocationCategoryCodeSimpleType',
'xsd:attributeGroup' => {
'ref' => 's:SimpleObjectAttributeGroup'
}
}
}
}
}
};
xsd:import
namespace : http://niem.gov/niem/structures/2.0
schemaLocation : ../../structures/2.0/structures.xsd
namespace : http://niem.gov/niem/appinfo/2.0
schemaLocation : ../../appinfo/2.0/appinfo.xsd
version
Can't use string ("1") as an ARRAY ref while "strict refs" in use at C:\Users\asraina\Downloads\script.pl line 16.
Теперь
- У меня есть правильное представление JSON? (Думаю нет, так как у меня ошибка)
- Каково будет правильное представление этой схемы в формате JSON?
Я не эксперт по Perl, меня больше беспокоит правильность представления JSON.