* xmlada validate schema trickery
@ 2011-10-14 14:19 björn lundin
2011-10-14 14:52 ` Emmanuel Briot
0 siblings, 1 reply; 3+ messages in thread
From: björn lundin @ 2011-10-14 14:19 UTC (permalink / raw)
Hi!
I'm using xmlada to validate some xmlfiles, and it works well.
function Validate(Xml, Xsd : in String) return Boolean is
Explicit_XSD : Boolean := False;
Read : File_Input;
Schema : Schema_Reader;
Grammar : XML_Grammar := No_Grammar;
My_Reader : Validating_Reader;
begin
if Xsd'length > 0 then
if Ada.Directories.Exists(Xsd) then
begin
Open (Xsd, Read);
Parse (Schema, Read);
Close (Read);
Explicit_XSD := True;
exception
when XML_Validation_Error =>
Close (Read);
raise;
end;
else
Feedback("File '" & Xsd & "' does not exist");
return False;
end if;
end if;
if Ada.Directories.Exists(Xml) then
if Explicit_XSD then
Grammar := Get_Created_Grammar(Schema);
Global_Check (Grammar);
end if;
xmlns="http://www.consafelogistics.com/sattmate"
Set_Validating_Grammar(My_Reader, Grammar);
Set_Feature(My_Reader, Schema_Validation_Feature, True);
Open(Xml, Read);
Parse(My_Reader, Read);
Close(Read);
Feedback("File '" & Xml & "' is valid");
return True;
else
Feedback("File '" & Xml & "' does not exist");
return False;
end if;
exception
when E : XML_Validation_Error | XML_Fatal_Error =>
Feedback(Exception_Message (E));
Close(Read);
return False;
when Ada.Io_Exceptions.Name_Error =>
Feedback("File '" & Xml & "' is not a valid filename");
return False;
end Validate;
----------------------------------------
this is called by
if Is_Set(Xsd) then
if Validate(Xml => Parameter(1),
Xsd => Value(Xsd)) then
Set_Exit_Status(Success);
end if;
else
if Validate(Xml => Parameter(1),
Xsd => "") then
Set_Exit_Status(Success);
end if;
end if;
where Value(Xsd)) holds xsd filename and Parameter(1) holds xml
filename
xml looks like
<?xml version="1.0" encoding="iso-8859-1"?>
<root_element xmlns="http://www.abc.com/some_namespace" >
<Term Name="goal" Type="9" Size="9">
</root_element>
and xsd
<?xml version='1.0' encoding='iso-8859-15'?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
xmlns='http://www.abc.com/some_namespace'
targetNamespace='http://www.abc.com/some_namespace'
elementFormDefault='qualified'
attributeFormDefault='unqualified'>
<xs:complexType name='goalType'>
<xs:sequence>
<xs:element name='goal' minOccurs='1' maxOccurs='1'/>
</xs:sequence>
</xs:complexType>
<xs:element name='MaAstro' type='xcl:goalType' />
</xs:schema>
This works well :-)
However, the xmlfiles are processed by some tcl-scripts as well,
and the (bad) tcldom(2.6) implementation (which I cannot upgrade)
crashes on the xmlns attribute
<root_element xmlns="http://www.abc.com/some_namespace" >
So I remove that so the xml looks like
<?xml version="1.0" encoding="iso-8859-1"?>
<root_element>
<Term Name="goal" Type="9" Size="9">
</root_element>
but then I get an error:
Element "goal": No matching declaration available
So, Im looking for a way to trick the parser to believe that
the xmlns="http://www.abc.com/some_namespace" attribute is there,
thus keeping me, tcl, and xmlada happy
Any suggestions?
/Björn
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xmlada validate schema trickery
2011-10-14 14:19 xmlada validate schema trickery björn lundin
@ 2011-10-14 14:52 ` Emmanuel Briot
2011-10-17 7:31 ` björn lundin
0 siblings, 1 reply; 3+ messages in thread
From: Emmanuel Briot @ 2011-10-14 14:52 UTC (permalink / raw)
> However, the xmlfiles are processed by some tcl-scripts as well,
> and the (bad) tcldom(2.6) implementation (which I cannot upgrade)
> crashes on the xmlns attribute
> <root_element xmlns="http://www.abc.com/some_namespace" >
Is this because of the null prefix (ie will it work if you use
xmlns:bjorn="..." and then use
<bjorn:root_element>
<bjorn:Term ...
...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xmlada validate schema trickery
2011-10-14 14:52 ` Emmanuel Briot
@ 2011-10-17 7:31 ` björn lundin
0 siblings, 0 replies; 3+ messages in thread
From: björn lundin @ 2011-10-17 7:31 UTC (permalink / raw)
On 14 Okt, 16:52, Emmanuel Briot <briot.emman...@gmail.com> wrote:
> > However, the xmlfiles are processed by some tcl-scripts as well,
> > and the (bad) tcldom(2.6) implementation (which I cannot upgrade)
> > crashes on the xmlns attribute
> > <root_element xmlns="http://www.abc.com/some_namespace" >
>
> Is this because of the null prefix (ie will it work if you use
> xmlns:bjorn="..." and then use
> <bjorn:root_element>
> <bjorn:Term ...
> ...
Hi Emmanuel!
I'm not quite sure I understand.
If I have
<?xml version="1.0" encoding="iso-8859-1"?>
<bjorn:root_element xmlns:bjorn='http://www.abc.com/some_namespace'>
<bjorn:Term Name="goal" Type="9" Size="9">
</bjorn:root_element>
I does work in xmlAda
but so does
<?xml version="1.0" encoding="iso-8859-1"?>
<root_element>
<Term Name="goal" Type="9" Size="9">
</root_element>
XmlAda is not my problem; tcldom2.6 is.
So the suggested solution still crashes the tcl-scripts.
But perhaps I misunderstood where to put the ns-declaration
My idea was to see if there is a way to tell XmlAda to treat
<root_element>
as if it really said
<root_element xmlns="http://www.abc.com/some_namespace" >
ie, 'just' append the xmlns attribute on the root node before/during
the validation
But I think I'll go for a simpler approch, I'll open the the file with
DOM first,
append the attribute, save it to a temp-file, and validate that one.
That, I think, is good enough, until I get to upgrade/replace the tcl-
scripts
/Björn
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-17 7:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-14 14:19 xmlada validate schema trickery björn lundin
2011-10-14 14:52 ` Emmanuel Briot
2011-10-17 7:31 ` björn lundin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox