Приведенный Вами пример работает.
А мой нет. =(
Работающий пример
PHP код:
static void XMLTry(Args _args)
{
XMLDocument xmlDoc = XMLDocument::newBlank();
XMLElement root, root2;
XMLAttribute attr1;
XMLNode docElem, docElem2;
XMLProcessingInstruction instruction;
XMLNode node;
;
// root element
root = xmlDoc.createNode(XMLNodeType::ELEMENT, "persons", "");
// inner element
root2 = xmlDoc.createNode(XMLNodeType::ELEMENT, "person1", "");
// attribute
attr1 = xmlDoc.createAttribute("attribute1");
root2.setAttribute("test", "child");
// assembly
docElem = xmlDoc.appendChild(root);
docElem2 = docElem.appendChild(root2);
// save
xmlDoc.save("c:\\test.xml");
}
Мой, не работающий ...
PHP код:
class CustTable2XML {
XMLDocument xmlDocument;
XMLElement xmlRootElement;
#CustTable
}
static void main (Args _args){
XMLDocument doc;
CustTable2XML cust2XML = new CustTable2XML() ;
;
doc = cust2XML.createXML();
print doc.toString();
doc.save('c:\\xxx.xml');
}
void new(){
;
xmlDocument = XMLDocument::newBlank();
xmlRootElement = xmlDocument.createElement(#CUSTTTABLE);
xmlDocument.appendChild(xmlRootElement);
}
public XMLDocument createXML() {
CustTable CustTable;
;
while select firstonly CustTable{
this.initCustTable(custtable);
}
return xmlDocument;
}
private void initCustTable(CustTable _custTable) {
XMLElement xmlElement;
str Trim (str _value) {
return strrtrim(strltrim(_value));
}
;
xmlElement = xmlDocument.createElement(#RECORD);
xmlElement.setAttribute(#ACCOUNTNUM , trim(_custTable.AccountNum));
xmlElement.setAttribute(#NAME , trim(_custTable.Name));
xmlElement.setAttribute(#ADDRESS , trim(_custTable.Address));
xmlRootElement.appendChild(xmlElement);
}
P.S причет, если закомментировать строку
xmlRootElement.appendChild(xmlElement); в методе
initCustTable, то файл создается (без информации о клиентах, конечно. Только заголовок и главный тэг с завершающим признаком, но с encoding )