CS157a
Chris Pollett
Dec 4, 2019
<patient type="out of state"> <![CDATA[This is data that will not be parsed by the XML parser even if it has tags in it like this: <tag>]]> <name><first>John</first><last>Smith</last></name> <insurerID>&kaiser;</insurerID> </patient>
<!ELEMENT element_name (list of names of child elements) SYSTEM Location NDATA NotationName >
<!ELEMENT memo (from, to, date) > ---- SYSTEM and NDATA don't have to used <!ELEMENT dept_script SYSTEM "dept.php" NDATA "php" > <!NOTATION php SYSTEM "/usr/bin/php" > <!ELEMENT person(parent+, age, spouse?, sibling*) > ---- + is one or more, ? is optional, and * is 0 or more <!ELEMENT element_name (#PCDATA) > ---- pcdata = parsable character data can also use EMPTY for no sub-tags or character data or ANY if you want to allow everything
<!ATTLIST element_name attribute_name_1 attribute_type [default_value] ... attribute_name_n attribute_type [default_value] >
<!ATTLIST airplane places CDATA "4"> <!ATTLIST airplane engine_type CDATA #REQUIRED> ---- must have the field <!ATTLIST airplane price CDATA #IMPLIED> ---- no default value is given <!ATTLIST airplane manufacturer CDATA #FIXED "cessna"> --- all instances must have the same value
<!ATTLIST img src CDATA #REQUIRED width CDATA #REQUIRED height CDATA #REQUIRED alt CDATA #IMPLIED >
<!ATTLIST horizontal_rule alignment (left|center|right) #IMPLIED >
<!ENTITY [%] entity_name "entity value" >% is used when it is a parameter entity
<!ENTITY cp "Chris Pollett" > <!ENTITY cool_pic SYSTEM "/usr/local/cool_pic.jpg">
<?xml version = "1.0" encoding ="utf-8" ?> <!-- planes_for_sale.dtd --> <!ELEMENT planes_for_sale (ad+) > <!ELEMENT ad (year, make, model, color, price?, seller) > <!ELEMENT year (#PCDATA)> <!ELEMENT make (#PCDATA)> <!ELEMENT model (#PCDATA)> <!ELEMENT color (#PCDATA)> <!ELEMENT price (#PCDATA)> <!ELEMENT seller (#PCDATA)> <!ATTLIST seller license CDATA #REQUIRED > <!ENTITY c "cessna" >
psql -d cpollett
CREATE TABLE TEST (BAR XML);
INSERT INTO TEST VALUES (XMLPARSE (CONTENT '<la><foo>bar</foo><bar>foo</bar></la>'));
SELECT XPATH('//foo', bar) FROM TEST;