Scott Lawrence wrote:
On Mon, 2010-02-01 at 18:14 +0200, Bogdan Brezoi wrote:
Hi,
I'm working on http://track.sipfoundry.org/browse/XX-7162 and I need
some advice/help regarding the transition from DTD to schema.
While most of the xml files are easy to change, there is one problem
with the tapestry.xml file. Basically, this xml file is validated by
DTD, but the problem is that it contains entities (as in DTD's <!
ENTITY ... >). From what I read and understood, XML schema doesn't
accept entities and I didn't find yet a suitable way to replace them.
These entities are used for text replacing, regarding some composed
regular expressions and they are defined as it follows:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"
[
<!-- Regexp fragments that are not atoms should be in (...), so that
modifiers ('?', '{...}', etc.) can be applied to them directly.
-->
<!-- see: http://www.ietf.org/rfc/rfc3261.txt -->
<!-- this is actually concatenation of unreserved and
user-unreserved sets -->
<!-- To be used only inside [...], and only at the beginning, as it
starts
with '-'. -->
<!ENTITY SIP_USER_UNRESERVED "-_.!~*'\(\)&=+$,;?/">
<!-- To be used only inside [...]. -->
<!ENTITY SIP_USER_CHARS "&SIP_USER_UNRESERVED;a-zA-Z0-9">
<!-- % is percent -->
<!ENTITY SIP_USER_ESCAPED "(%[0-9a-fA-F]{2})">
<!ENTITY SIP_USER_REGEX "(\[\])">
<!-- One octet of an IP address. (Allows leading zeros, up to 3
digits.) -->
<!ENTITY IP_ADDR_OCTET "(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})">
<!ENTITY IP_ADDR "(&IP_ADDR_OCTET;\.&IP_ADDR_OCTET;\.&IP_ADDR_OCTET;
\.&IP_ADDR_OCTET;)">
<!-- Components of DNS names, per RFC 1034 section 3.5. -->
<!ENTITY DNS_LET_DIG "[A-Za-z0-9]">
<!ENTITY DNS_LET_DIG_HYP "[-A-Za-z0-9]">
<!ENTITY DNS_LABEL
"(&DNS_LET_DIG;(&DNS_LET_DIG_HYP;*&DNS_LET_DIG;)?)">
<!-- DNS domain names have at least 2 labels, of which the last
contains
only letters and has at least 2 chars. 'localhost' is also
allowed.. -->
<!ENTITY DNS_DOMAIN_NAME "((&DNS_LABEL;\.){1,}[A-Za-z]{2,}|
localhost)">
]>
I would be really grateful if someone could help me with this.
The way I see it now. there are two ways to get past this:
- get rid of the entities and directly replace the references with the
full text in the xml file (that would result in having some pretty
nasty regular expressions in xml).
- leave the tapestry.xml as it is for now, validating it by DTD, and
maybe someone could come up with a proper change for it in the future.
What do you think? Am I missing something? Is there another way to do
this?
Each of those is, I assume, being used to validate the content of
various elements and/or attributes.
Actually, each entity is not used to validate elements/attributes but as
a place-holder. The actual value of the entity is used to replace its
entity reference in some text. Below is an example in which the value of
the "pattern" property is calculated by referring the entities
SIP_USER_CHARS and SIP_USER_ESCAPED.
|<bean name="validPhoneOrAor"
class="org.apache.tapestry.form.validator.Pattern">
<property name="pattern">
<value>([+]?[\d*]+)|([&SIP_USER_CHARS;]|&SIP_USER_ESCAPED;)+...@\w[-._\w]*\w\.\w{2,6}</value>
</property>
<property name="message">
<value>Please enter digits or sip address only, for example: 123
or [email protected]</value>
</property>
</bean>|
The way to model this in an XML Schema is to create a type - the type
extends some base string type and adds a restriction that constrains the
string content. Then the elements and attributes are declared to have
that type rather than just string. (This is one of the things that
distinguishes an xml schema from a dtd).
You can see examples of this in several of the existing xsd files - see
sipXproxy/meta/call_event.xsd
_______________________________________________
sipx-dev mailing list [email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev
Unsubscribe: http://list.sipfoundry.org/mailman/listinfo/sipx-dev
sipXecs IP PBX -- http://www.sipfoundry.org/