XML e namespace
copia linkDescrizione
E' stata introdotta la gestione del namespace dei nodi e degli attributi nell'XML. In particolare è stata aggiunta la funzione Namespace ed il parametro omonimo nei metodi AddElement, SetTextNode, SetAttribute, GetAttribute, GetNextAttribute.
Esempio di codice
XMLDocument doc = new()
XMLNode root = doc.addElement("root", ...)
//
XMLNode tableH = root.addElement("h:table", "http://www.w3.org/TR/html4/")
XMLNode trH = tableH.addElement("h:tr", "http://www.w3.org/TR/html4/")
XMLNode tdH1 = trH.setTextNode("h:td", "Apples", "http://www.w3.org/TR/html4/")
XMLNode tdH2 = trH.setTextNode("h:td", "Apples", "http://www.w3.org/TR/html4/")
//
XMLNode tableF = root.addElement("f:table", "https://www.w3schools.com/furniture")
XMLNode trF = tableF.addElement("f:tr", "https://www.w3schools.com/furniture")
XMLNode nameF = trF.setTextNode("f:name", "African Coffee Table", "https://www.w3schools.com/furniture")
XMLNode widthF = trF.setTextNode("f:width", "80", "https://www.w3schools.com/furniture")
XMLNode lengthF = trF.setTextNode("f:length", "120", "https://www.w3schools.com/furniture")
//
string xml = doc.saveToString(...)
XMLNode root = doc.addElement("root", ...)
//
XMLNode tableH = root.addElement("h:table", "http://www.w3.org/TR/html4/")
XMLNode trH = tableH.addElement("h:tr", "http://www.w3.org/TR/html4/")
XMLNode tdH1 = trH.setTextNode("h:td", "Apples", "http://www.w3.org/TR/html4/")
XMLNode tdH2 = trH.setTextNode("h:td", "Apples", "http://www.w3.org/TR/html4/")
//
XMLNode tableF = root.addElement("f:table", "https://www.w3schools.com/furniture")
XMLNode trF = tableF.addElement("f:tr", "https://www.w3schools.com/furniture")
XMLNode nameF = trF.setTextNode("f:name", "African Coffee Table", "https://www.w3schools.com/furniture")
XMLNode widthF = trF.setTextNode("f:width", "80", "https://www.w3schools.com/furniture")
XMLNode lengthF = trF.setTextNode("f:length", "120", "https://www.w3schools.com/furniture")
//
string xml = doc.saveToString(...)
Con questo codice si ottiene questo xml:
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="https://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
Funzionalità interessate
Lettura/scrittura di XML con namespace dei nodi e attributi.
Note
- Miglioramento relativo a questo thread del forum.
- Miglioramento relativo alla proposta di modifica PRP000356.
Con questo codice si ottiene questo xml:
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="https://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
Ultima modifica: 11/10/2019 / Validità: da 19.5.7600