XML operation method

xiaoxiao2021-03-06  85

/// method name: XpathQueryFromxml

///Input parameters:

/// pfilename: file name

/// ProT: The root of the element

/// Pattribute: Attribute Name

/// PattributeValue: attribute value

/// Return value: the value of this element, String type

Public XMLNode LoadValue (String XPath, INT INDEX)

{

XMLnodelist NL = Xml.selectNodes (XPATH);

Return nl.item (index);

}

Public String XPathFromxml (String Proot, String Pattribute, String PattributeValue)

{

String svalue = "error.";

String sxpath = "//" proot "/ * [@" pattribute "= '" pattributevalue ";";

Try

{

XMLNode Nd = Xml.selectsingLenode (SXPATH);

Svalue = nd.innertext.toString ();

}

Catch (Exception E)

{

ApplicationLog.writelog (e.tostring ());

}

Return Svalue;

}

/// method name: AddValuetoxML

/// Function: Add the specified XMLNode to the specified location of the specified file

///Input parameters:

/// pfilename: file name

/// pelementname: element name

/// pValue: value of elements

/// Pattribute: Attribute Name

/// PattributeValue: attribute value

/// ProT: The root of the element

/// Return value: no

Public void addvaluetoxetoxetoXML (String PROT, STRING PelementName, String Pattribute, String PValue)

{

Try

{

Xmlelement root = xml.documentelement;

XMLNode Nd = root [ProT];

XMLELEMENT NEL = Xml.createElement (pelementname);

NEL.SetAttribute (Pattribute, Pattributevalue);

NEL.INNNERTEXT = PVALUE;

nd.appendchild (nel);

Xml.save (M_ConfigFileName);

}

Catch (Exception E)

{

ApplicationLog.writelog (e.tostring ());

}

}

/// method name: updatevaluetoxml by JSZ AT 2003.1.23

/// function: Modify the specified location of the specified file, match according to the element name attribute value

///Input parameters:

/// pfilename: file name

/// ProT: The root of the element

/// pelementname: element name

/// Pattribute: Attribute Name

/// PattributeValue: attribute value

/// pValue: Element value to replace /// return value: BOOL type, success or not

Public Bool UpdatevaluetoxML (String PROOT, STRING PelementName, String Pattribute, String PVALUE, STRING PVALUE)

{

Bool svalue = false;

String sxpath = "//" proot "/" pelementname "[@" pattribute "= '" pattyvalue ";";

Try

{

XMLNode Nd = Xml.selectsingLenode (SXPATH);

nd.innertext = PVALUE;

Xml.save (M_ConfigFileName);

Svalue = true;

}

Catch (Exception E)

{

ApplicationLog.writelog (e.tostring ());

}

Return Svalue;

}

/// method name: deleteFromxml by JSZ AT 2003.1.23

/// Function: Delete the node from the specified location of the specified file, match according to the element name attribute value

///Input parameters:

/// pfilename: file name

/// ProT: The root of the element

/// pelementname: element name

/// Pattribute: Attribute Name

/// PattributeValue: attribute value

/// Return value: Bool type, successful identification

Public Bool DeleteFroml (String Proot, String PelementName, String Pattribute, String PattributeValue)

{

Bool svalue = false;

String sxpath = "//" proot "/" pelementname "[@" pattribute "= '" pattyvalue ";";

String sxpathroot = "//" propot;

Try

{

XMLNode Nd = Xml.selectsingLenode (SXPATH);

XMLNode root = Xml.selectsinglenode (SXPathRoot);

Nd.RemoveChild (ND);

Xml.save (M_ConfigFileName);

Svalue = true;

}

Catch (Exception E)

{

ApplicationLog.writelog (e.tostring ());

}

Return Svalue;

}

转载请注明原文地址:https://www.9cbs.com/read-95800.html

New Post(0)