Re: XML validation of whitespace values

Поиск
Список
Период
Сортировка
От David G Johnston
Тема Re: XML validation of whitespace values
Дата
Msg-id 1399857521822-5803594.post@n5.nabble.com
обсуждение исходный текст
Ответ на XML validation of whitespace values  (Tim Kane <tim.kane@gmail.com>)
Список pgsql-general
Tim Kane wrote
> clone=# create temp table xml_test (document xml);
> CREATE TABLE

If you know you need to use xpath on this content then you should do one of
the following:

SELECT CASE WHEN document IS DOCUMENT THEN xpath(...) ELSE
default_value_for_missing_data END;

CREATE TABLE xml_test (
document xml NOT NULL CHECK (document IS DOCUMENT)
);

For better and worse in the name of "simplicity" both xml and json(b?) types
are usable for both the embedded content and the entire document.  Unless
you think you have a good reason for a single column to represent both
content and documents you should probably constrain stored data to be
whichever you are expecting.  This is the root of your confusion since, as
Peter said, xpathing only operates on documents - not content fragments.

"The second argument must be a well formed XML document. In particular, it
must have a single root node element."

Unfortunately the decision to treat documents and content as the same types
means this cannot be discovered at parse-time but is data dependent and thus
a run-time error.  By putting in the constraint you ensure that any use of
said column in an xpath query will either always succeed or always fail.

Furthermore:

"xml_is_well_formed does the former if the xmloption configuration parameter
is set to DOCUMENT, or the latter if it is set to CONTENT" - the default for
xmloption is CONTENT...

Both quotes above come from:

http://www.postgresql.org/docs/9.3/interactive/functions-xml.html

David J.







--
View this message in context:
http://postgresql.1045698.n5.nabble.com/XML-validation-of-whitespace-values-tp5796092p5803594.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


В списке pgsql-general по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: XML validation of whitespace values
Следующее
От: "Felix Kunde"
Дата:
Сообщение: comparing two JSON objects in 9.3