Commits

Anonymous committed ee050bd

Added the first IRC example.

Comments (0)

Files changed (4)

XML-Grammar-Fortune/module/MANIFEST

 Build.PL
 Changes
+extradata/fortune-xml.rng
 inc/Test/Run/Builder.pm
 lib/XML/Grammar/Fortune.pm
+Makefile.PL
 MANIFEST
+META.yml
 README
 t/00-load.t
+t/data/xml/irc-conversation-1.xml
 t/pod-coverage.t
 t/pod.t
-Makefile.PL
-META.yml
+t/xml-validate.t

XML-Grammar-Fortune/module/extradata/fortune-xml.rng

+<?xml version="1.0"?>
+<!-- $Id: testSuite.rng,v 1.12 2003/01/29 12:24:07 jjc Exp $ -->
+<grammar xmlns="http://relaxng.org/ns/structure/1.0">
+    <start>
+        <element name="collection">
+            <element name="head">
+                <empty/>
+            </element>
+            <element name="list">
+                <oneOrMore>
+                    <ref name="fortune" />
+                </oneOrMore>
+            </element>
+        </element>
+    </start>
+    <define name="fortune">
+        <element name="fortune">
+            <attribute name="id">
+            </attribute>
+            <choice>
+                <element name="irc">
+                    <element name="body">
+                        <oneOrMore>
+                            <choice>
+                                <element name="saying">
+                                    <attribute name="who">
+                                        <text/>
+                                    </attribute>
+                                    <text/>
+                                </element>
+                                <element name="me_is">
+                                    <attribute name="who">
+                                        <text/>
+                                    </attribute>
+                                    <text/>
+                                </element>
+                                <element name="joins">
+                                    <attribute name="who">
+                                        <text/>
+                                    </attribute>
+                                    <text/>
+                                </element>
+                                <element name="leaves">
+                                    <attribute name="who">
+                                        <text/>
+                                    </attribute>
+                                    <text/>
+                                </element>
+                            </choice>
+                        </oneOrMore>
+                    </element>
+                    <element name="info">
+                        <optional>
+                            <element name="channel">
+                                <text />
+                            </element>
+                        </optional>
+                        <optional>
+                            <element name="network">
+                                <text />
+                            </element>
+                        </optional>
+                        <optional>
+                            <element name="date">
+                                <text />
+                            </element>
+                        </optional>
+                        <optional>
+                            <element name="tagline">
+                                <text />
+                            </element>
+                        </optional>
+                    </element>
+                </element>
+            </choice>
+        </element>
+    </define>
+</grammar>

XML-Grammar-Fortune/module/t/data/xml/irc-conversation-1.xml

+<?xml version="1.0" encoding="utf-8"?>
+<collection>
+    <head />
+    <list>
+        <fortune id="I-need-to-get-a-life">
+            <irc>
+                <body>
+                    <saying who="rindolf">LeoNerd: I need to get a life.</saying>
+                    <saying who="LeoNerd">They can be quite useful, but they do have a crazy amount of dependencies..</saying>
+                    <saying who="LeoNerd">And sometimes they can be a bit unstable - I think they're still beta-testing</saying>
+                </body>
+                <info>
+                    <channel>#perl</channel>
+                    <network>Freenode</network>
+                    <tagline>Geek Humour</tagline>
+                </info>
+            </irc>
+        </fortune>
+    </list>
+</collection>

XML-Grammar-Fortune/module/t/xml-validate.t

+#===============================================================================
+#
+#         FILE:  xml-validate.t
+#
+#  DESCRIPTION:  
+#
+#        FILES:  ---
+#         BUGS:  ---
+#        NOTES:  ---
+#       AUTHOR:  Shlomi Fish (SHLOMIF), <shlomif@iglu.org.il>
+#      COMPANY:  None
+#      VERSION:  1.0
+#      CREATED:  05/05/08 13:34:28 IDT
+#     REVISION:  ---
+#===============================================================================
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;                      # last test to print
+
+use XML::LibXML;
+
+my $doc = XML::LibXML->new->parse_file("./t/data/xml/irc-conversation-1.xml");
+
+my $rngschema = XML::LibXML::RelaxNG->new(
+    location => "./extradata/fortune-xml.rng" 
+);
+
+my $code;
+$code = $rngschema->validate($doc);
+
+# TEST
+ok ((defined($code) && ($code == 0)),
+    "The validation succeeded.") ||
+    diag("\$@ == $@");
+