![]() |
Use this table as a quick reference to XML syntax. The Java code is based on the TX compatibility classes.
The APIs below are significantly back-level
compared to the XML API versions currently available. If you use them, it is likely
you will need to migrate your code to the newer APIs in the near future. See the
Related information below for a full discussion.
XML object | XML syntax | Example Java code based on TX compatibility classes |
XML declaration |
<?xml version="1.0" encoding="ISO-8859-1"?> |
TXDocument doc = new TXDocument(); doc.setVersion("1.0"); doc.setEncoding("ISO-8859-1"); |
Processing instruction |
<?PINname data?> |
TXPI pi = (TXPI) doc.createProcessingInstruction ("PIname","data"); |
Processing instruction |
<?PINname?> |
TXPI pi = (TXPI) doc.createProcessingInstruction ("PIname",""); |
XML comment |
<-- comment text --> |
TXComment comm = (TXComment) doc.createComment ("comment text"); |
Inline DTD declaration |
<!DOCTYPE state [...]> |
DTD dtd = doc.createDTD("state", null); dtd.addElement(...); |
External DTD declaration |
<!DOCTYPE state SYSTEM "state.dtd"> |
DTD dtd = doc.createDTD("state", new) ExternalID("state.dtd")); |
Empty root element |
<!ELEMENT state EMPTY> |
ElementDecl ed = factory.createElementDecl("state", factory.createContentModel(ElementDecl.EMPTY)); |
Element content model |
<!ELEMENT state (#PCDATA|city)*; |
CMNode model = new CM1op('*', new CM2op('|', new CM2op('|', new CMLeaf("#PCDATA"), new CMLeaf("city"))); ContentModel cm = factory.createContentModel(model); ElementDecl ed = factory.createElementDecl("state", cm); |
Element content model |
<!ELEMENT state (#PCDATA|city)*; |
ContentModel cm = factory.createContentModel(ElementDecl.MODEL_GROUP); cm.setPseudoContentModel("(#PCDATA|FOO|BAR)*"); ElementDecl ed = factory.createElementDecl("ROOT", cm); A DTD that includes this instance cannot be used for validation. It can be used for only printing. |
Element content model |
<!ELEMENT state (name?, (population|numpeople)+, street*); |
CMNode model = new CM2op(',', new CM2op(',', new CM1op('?', new CMLeaf("capitol")), new CM1op('+', new CM2op('|', new CMLeaf("population"), new CMLeaf("numpeople")))), new CM1op('*', new CMLeaf("city"))); ContentModel cm = factory.createContentModel(model); ElementDecl ed = factory.createElementDecl("state", cm); |
Element content model |
<!ELEMENT state (name?, (population|numpeople)+, street*); |
ContentModel cm = factory.createContentModel(ElementDecl.MODEL_GROUP); cm.setPseudoContentModel("(capitol?, (population|numpeople)+, city*)"); ElementDecl ed = factory.createElementDecl("state", cm); A DTD that includes this instance cannot be used for validation. It can be used for only printing. |
Attribute declaration |
<!ATTLIST state att1 CDATA #IMPLIED att2 (A|B|O|AB) "A"> |
Attlist al = factory.createAttlist("state"); AttDef ad = factory.createAttDef("att1"); ad.setDeclaredType(AttDef.CDATA); ad.setDefaultType(AttDef.IMPLIED); al.addElement(ad); ad = factory.createAttDef("att2"); ad.setDeclaredType(AttDef.NAME_TOKEN_GROUP); ad.addElement("A"); ad.addElement("B"); ad.addElement("O"); ad.addElement("AB"); ad.setDefaultStringValue("A"); al.addElement(ad); A DTD that includes this instance cannot be used for validation. It can be used for only printing. |
Entity declaration for inline DTD |
<!ENTITY version "1.1.6">> |
Entity ent = factory.createEntity("version", "1.1.6", false); |
Entity declarartion for external DTD |
Entity ent = factory.createEntity("version", new ExternalID("versionent"), null); |
Entity ent = factory.createEntity("version", "1.1.6", false); |
General entity reference |
&version; |
GeneralReference gr = factory.createGeneralReference("version"); |
General entity reference for unparsed data |
<!ENTITY logoicon SYSTEM "logo.gif" NDATA gif> |
Entity ent = factory.createEntity("logoicon", new ExternalID("logo.gif"), "gif"); |
Notation declaration |
<!NOTATION gif SYSTEM "browser.exe"> |
TXNotation no = doc.createNotation("gif", new ExternalID("browser.exe")); |
XML element and content |
<state att1="stateid">any text</state> |
TXElement el = factory.createElement("state"); el.setAttribute("stateid", "MN"); el.addElement(factory.createText("any text")); |
CDATA section |
<![CDATA[any text]]> |
TXCDATASection cd = factory.createCDATASection("any text"); |
|