return setProperty(parent, name, value, caseSensitive);
}
// Name
else if(k.equals(XMLNAME)) {
throw new XMLException("You can't assign a new value for the property [xmlname]");
}
// Type
else if(k.equals(XMLTYPE)) {
throw new XMLException("You can't change type of a xml node [xmltype]");
}
// value
else if(k.equals(XMLVALUE)) {
node.setNodeValue(Caster.toString(value));
}
// Attributes
else if(k.equals(XMLATTRIBUTES)) {
Element parent=XMLCaster.toElement(doc,node);
Attr[] attres=XMLCaster.toAttrArray(doc,value);
//print.ln("=>"+value);
for(int i=0;i<attres.length;i++) {
if(attres[i]!=null) {
parent.setAttributeNode(attres[i]);
//print.ln(attres[i].getName()+"=="+attres[i].getValue());
}
}
}
// Text
else if(k.equals(XMLTEXT)) {
removeChildCharacterData(XMLCaster.toRawNode(node),false);
node.appendChild(XMLCaster.toRawNode(XMLCaster.toText(doc,value)));
}
// CData
else if(k.equals(XMLCDATA)) {
removeChildCharacterData(XMLCaster.toRawNode(node),false);
node.appendChild(XMLCaster.toRawNode(XMLCaster.toCDATASection(doc,value)));
}
// Children
else if(k.equals(XMLCHILDREN) || k.equals(XMLNODES)) {
Node[] nodes=XMLCaster.toNodeArray(doc,value);
removeChildren(XMLCaster.toRawNode(node),Node.ELEMENT_NODE,false);
for(int i=0;i<nodes.length;i++) {
if(nodes[i]==node) throw new XMLException("can't assign a XML Node to himself");
if(nodes[i]!=null)node.appendChild(XMLCaster.toRawNode(nodes[i]));
}
}
else {
boolean isIndex=false;
Node child = XMLCaster.toNode(doc,value,false);
if(!k.getString().equalsIgnoreCase(child.getNodeName()) && !(isIndex=Decision.isInteger(k))) {
throw new XMLException("if you assign a XML Element to a XMLStruct , assignment property must have same name like XML Node Name", "Property Name is "+k.getString()+" and XML Element Name is "+child.getNodeName());
}
Node n;
// by index
if(isIndex) {
NodeList list = XMLUtil.getChildNodes(node.getParentNode(), Node.ELEMENT_NODE,true,node.getNodeName());
int len = list.getLength();
int index=Caster.toIntValue(k);
if(index>len || index<1){
String detail=len>1?
"your index is "+index+", but there are only "+len+" child elements":
"your index is "+index+", but there is only "+len+" child element";
throw new XMLException("index is out of range", detail);
}
n=list.item(index-1);
XMLUtil.replaceChild(child, n);
return value;
}