Skip to content

Commit

Permalink
* Attribute qualification in XML mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker committed Sep 16, 2002
1 parent 87dc60d commit 118ad21
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* MODIFIED/ADDED: qualify_attributes option for xmlns mode. Default is
now *not* to qualify attributes.

* FIXED: Handle elements inside shorttag values. Thanks Richard O'Keefe
for providing a clear description how to handle this.

Expand Down
4 changes: 3 additions & 1 deletion Test/netc.sgml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<!DOCTYPE shref [
<!ELEMENT shref - - (netc|twit)*>
<!ELEMENT shref - - (netc|twit|twat)*>
<!ELEMENT netc - - (frob+)>
<!ELEMENT frob O O (twit)>
<!ELEMENT twit - O (#PCDATA)>
<!ELEMENT twat - - CDATA>
]>
<shref>
<netc/<frob><twit>This slash should end netc:/
<twat/This is a twat/
<twit/This is a simple shortref/
</shref>
2 changes: 1 addition & 1 deletion Test/ok/netc.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[element(shref, [], [element(netc, [], [element(frob, [], [element(twit, [], ['This slash should end netc:'])])]), element(twit, [], ['This is a simple shortref'])])].
[element(shref, [], [element(netc, [], [element(frob, [], [element(twit, [], ['This slash should end netc:'])])]), element(twat, [], ['This is a twat']), element(twit, [], ['This is a simple shortref'])])].
[].
26 changes: 18 additions & 8 deletions doc/sgml2pl.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<center>

<h1>SWI-Prolog SGML/XML parser<br>
<font size="+0"><em>Version 1.0.14, March 2001</em></font></h1>
<font size="+0"><em>Version 1.0.15, September 2002</em></font></h1>

<br>
<a href="mailto:[email protected]"><em>Jan Wielemaker</em></a><br>
Expand Down Expand Up @@ -823,7 +823,7 @@ <h2><a name="sec:sec-3.4">DTD-Handling</a></h2>

<dt>&nbsp;<br>
<b>notation(<var>Name, Decl</var>)</b><dd>
Unify <var>Decl</var> with a list if <code>system(+File)</code> and/or
Unify <var>Decl</var> with a list if <code>system(+File)</code> andor
<code>public(+PublicId)</code>.
</dl>
</dl>
Expand Down Expand Up @@ -962,10 +962,20 @@ <h2><a name="sec:sec-3.6">Parsing Primitives</a></h2>
<dt>&nbsp;<br>
<b><a name="const:xmlns%5"><b><tt>xmlns</tt></b></a></b><dd>
Process file as XML file with namespace support. See <a href="#sec:xmlns">xmlns</a> for
details.
details. See also the <code>qualify_attributes</code> option below.
</dl>


<dt>&nbsp;<br>
<b>qualify_attributes(<var>Boolean</var>)</b><dd>
How to handle unqualified attribute (i.e. without an explicit namespace)
in XML namespace (<a name="const:xmlns%6"><b><tt>xmlns</tt></b></a>) mode. Default and standard compliant
is not to qualify such elements. If <a name="const:true%2"><b><tt>true</tt></b></a>, such attributes are qualified
with the namespace of the element they appear in. This option is for
backward compatibility as this is the behaviour of older versions. In
addition, the namespace document suggests unqualified attributes are
often interpreted in the namespace of their element.

<dt>&nbsp;<br>
<b>space(<var>SpaceMode</var>)</b><dd>
Define the initial handling of white-space in PCDATA. This attribute is
Expand Down Expand Up @@ -1024,7 +1034,7 @@ <h2><a name="sec:sec-3.6">Parsing Primitives</a></h2>

<dt>&nbsp;<br>
<b>dialect(<var>-Dialect</var>)</b><dd>
Return the current dialect used by the parser (<a name="const:sgml%5"><b><tt>sgml</tt></b></a>, <a name="const:xml%4"><b><tt>xml</tt></b></a> or <a name="const:xmlns%6"><b><tt>xmlns</tt></b></a>).
Return the current dialect used by the parser (<a name="const:sgml%5"><b><tt>sgml</tt></b></a>, <a name="const:xml%4"><b><tt>xml</tt></b></a> or <a name="const:xmlns%7"><b><tt>xmlns</tt></b></a>).


<dt>&nbsp;<br>
Expand Down Expand Up @@ -1278,14 +1288,14 @@ <h2><a name="sec:sec-3.6">Parsing Primitives</a></h2>

<dt>&nbsp;<br>
<b>xmlns</b><dd>
When parsing an in <a name="const:xmlns%7"><b><tt>xmlns</tt></b></a> mode, a new namespace declaraction is
When parsing an in <a name="const:xmlns%8"><b><tt>xmlns</tt></b></a> mode, a new namespace declaraction is
pushed on the environment. The named handler is called with three
arguments: <code><var>Handler</var>(+NameSpace, +URL, +Parser)</code>.
See <a href="#sec:xmlns">xmlns</a> for details.

<dt>&nbsp;<br>
<b>urlns</b><dd>
When parsing an in <a name="const:xmlns%8"><b><tt>xmlns</tt></b></a> mode, this predicate can be used to map a
When parsing an in <a name="const:xmlns%9"><b><tt>xmlns</tt></b></a> mode, this predicate can be used to map a
url into either a canonical URL for this namespace or another internal
identifier. See <a href="#sec:xmlns">xmlns</a> for details.
</dl>
Expand Down Expand Up @@ -1761,13 +1771,13 @@ <h1>Index</h1>
<li><a href="#const:shorttag"><b><tt>shorttag</tt></b></a>
<li><a href="#const:start"><b><tt>start</tt></b></a>
<li><a href="#const:token"><b><tt>token</tt></b></a> [ <a href="#const:token%2">2</a>]
<li><a href="#const:true"><b><tt>true</tt></b></a>
<li><a href="#const:true"><b><tt>true</tt></b></a> [ <a href="#const:true%2">2</a>]
<li><a href="#const:urlns"><b><tt>urlns</tt></b></a>
<li><a href="#const:warning"><b><tt>warning</tt></b></a>
<li><a href="#const:xml"><b><tt>xml</tt></b></a> [ <a href="#const:xml%2">2</a> <a href="#const:xml%3">3</a> <a href="#const:xml%4">4</a>]
<li><a href="#xml_quote_attribute/2"><b>xml_quote_attribute/2</b></a>
<li><a href="#xml_quote_cdata/2"><b>xml_quote_cdata/2</b></a>
<li><a href="#const:xmlns"><b><tt>xmlns</tt></b></a> [ <a href="#const:xmlns%2">2</a> <a href="#const:xmlns%3">3</a> <a href="#const:xmlns%4">4</a> <a href="#const:xmlns%5">5</a> <a href="#const:xmlns%6">6</a> <a href="#const:xmlns%7">7</a> <a href="#const:xmlns%8">8</a>]
<li><a href="#const:xmlns"><b><tt>xmlns</tt></b></a> [ <a href="#const:xmlns%2">2</a> <a href="#const:xmlns%3">3</a> <a href="#const:xmlns%4">4</a> <a href="#const:xmlns%5">5</a> <a href="#const:xmlns%6">6</a> <a href="#const:xmlns%7">7</a> <a href="#const:xmlns%8">8</a> <a href="#const:xmlns%9">9</a>]
</ul>
</body>
</html>
Binary file modified doc/sgml2pl.pdf
Binary file not shown.
14 changes: 11 additions & 3 deletions doc/sgml2pl.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<pldoc>
<head>
<version>1.0.14
<release-date>March 2001
<version>1.0.15
<release-date>September 2002
<package>sgml2pl
</head>

Expand Down Expand Up @@ -706,8 +706,16 @@ This dialect is selected automatically if the processing instruction
<verb><?xml ...></verb> is encountered. See <ref sec/xml/ for details.
<termitem><c/xmlns/
Process file as XML file with namespace support. See <ref sec/xmlns/ for
details.
details. See also the <verb>qualify_attributes</verb> option below.
</argdef>
<termitem>qualify_attributes(Boolean)
How to handle unqualified attribute (i.e. without an explicit namespace)
in XML namespace (<c/xmlns/) mode. Default and standard compliant
is not to qualify such elements. If <c/true/, such attributes are qualified
with the namespace of the element they appear in. This option is for
backward compatibility as this is the behaviour of older versions. In
addition, the namespace document suggests unqualified attributes are
often interpreted in the namespace of their element.
<termitem>space(SpaceMode)
Define the initial handling of white-space in PCDATA. This attribute is
described in <ref sec/space/.
Expand Down
25 changes: 22 additions & 3 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3366,7 +3366,9 @@ process_net(dtd_parser *p)
p->first = FALSE;

if ( p->on_end_element )
(*p->on_end_element)(p, env->element);
{ WITH_CLASS(p, EV_SHORTTAG,
(*p->on_end_element)(p, env->element));
}

free_environment(env);
p->environments = parent;
Expand Down Expand Up @@ -4459,7 +4461,8 @@ putchar_dtd_parser(dtd_parser *p, int chr)
}

if ( p->waiting_for_net && f[CF_ETAGO2] == chr ) /* shorttag */
{ WITH_PARSER(p,
{ setlocation(&p->startloc, &p->location, line, lpos);
WITH_PARSER(p,
process_net(p));
return;
}
Expand Down Expand Up @@ -4523,7 +4526,23 @@ putchar_dtd_parser(dtd_parser *p, int chr)
if ( f[CF_MDO1] == chr ) /* < */
{ setlocation(&p->startloc, &p->location, line, lpos);
p->state = S_ECDATA1;
}
}

/* / in CDATA shorttag element */
if ( p->waiting_for_net && f[CF_ETAGO2] == chr )
{ setlocation(&p->startloc, &p->location, line, lpos);
p->cdata->size--;
terminate_ocharbuf(p->cdata);
terminate_icharbuf(p->buffer);
if ( p->mark_state == MS_INCLUDE )
{ WITH_PARSER(p,
process_cdata(p, TRUE);
process_net(p));
empty_cdata(p);
}
empty_icharbuf(p->buffer);
p->cdata_state = p->state = S_PCDATA;
}

return;
}
Expand Down

0 comments on commit 118ad21

Please sign in to comment.