namespace com.hitrust.trustpay.client
|
|
{
|
|
using System;
|
|
using System.Collections;
|
|
|
|
public class XMLDocument
|
|
{
|
|
private string iXMLString;
|
|
|
|
public XMLDocument()
|
|
{
|
|
this.iXMLString = "";
|
|
}
|
|
|
|
public XMLDocument(string aXMLString)
|
|
{
|
|
this.iXMLString = "";
|
|
this.init(aXMLString);
|
|
}
|
|
|
|
public virtual XMLDocument deleteFirstTagDocument()
|
|
{
|
|
string tTagName = this.getFirstTagName();
|
|
int tStartIndex = this.iXMLString.IndexOf("<" + tTagName + ">");
|
|
int tEndIndex = this.iXMLString.IndexOf("</" + tTagName + ">");
|
|
if (tEndIndex > tStartIndex) {
|
|
this.iXMLString = this.iXMLString.Substring((tEndIndex + tTagName.Length) + 3);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public virtual ArrayList getDocuments(string aTag)
|
|
{
|
|
string tXMLString = this.iXMLString;
|
|
ArrayList tValues = new ArrayList();
|
|
while (true) {
|
|
XMLDocument tXMLDocument = null;
|
|
int tStartIndex = tXMLString.IndexOf("<" + aTag.Trim() + ">");
|
|
int tEndIndex = tXMLString.IndexOf("</" + aTag.Trim() + ">");
|
|
if (((tStartIndex == -1) || (tEndIndex == -1)) || (tStartIndex > tEndIndex)) {
|
|
return tValues;
|
|
}
|
|
tXMLDocument = new XMLDocument(tXMLString.Substring(tStartIndex, ((tEndIndex + aTag.Length) + 3) - tStartIndex));
|
|
tValues.Add(tXMLDocument);
|
|
tXMLString = tXMLString.Substring(tEndIndex + 1);
|
|
}
|
|
}
|
|
|
|
public virtual string getFirstTagName()
|
|
{
|
|
string tTagName = null;
|
|
int tStartIndex = this.iXMLString.IndexOf('<');
|
|
int tEndIndex = this.iXMLString.IndexOf('>');
|
|
if (tEndIndex > tStartIndex) {
|
|
tTagName = this.iXMLString.Substring(tStartIndex + 1, tEndIndex - (tStartIndex + 1));
|
|
}
|
|
return tTagName;
|
|
}
|
|
|
|
public virtual XMLDocument getFormatDocument(string aSpace)
|
|
{
|
|
return this.getFormatDocument(0, aSpace);
|
|
}
|
|
|
|
private XMLDocument getFormatDocument(int aLevel, string aSpace)
|
|
{
|
|
string tTagName;
|
|
string tSpace1 = aSpace;
|
|
for (int i = 0; i < aLevel; i++) {
|
|
tSpace1 = tSpace1 + aSpace;
|
|
}
|
|
if (this.getFirstTagName() == null) {
|
|
return this;
|
|
}
|
|
string tXMLString = "\n";
|
|
for (XMLDocument tXMLDocument = new XMLDocument(this.iXMLString); (tTagName = tXMLDocument.getFirstTagName()) != null; tXMLDocument = tXMLDocument.deleteFirstTagDocument()) {
|
|
XMLDocument tTemp = tXMLDocument.getValue(tTagName);
|
|
string tSpace = "";
|
|
if (tTemp.getFirstTagName() != null) {
|
|
tSpace = tSpace1;
|
|
}
|
|
tXMLString = string.Concat(new object[] {tXMLString, tSpace1, "<", tTagName, ">", tTemp.getFormatDocument(aLevel + 1, aSpace), tSpace, "</", tTagName, ">\n"});
|
|
}
|
|
return new XMLDocument(tXMLString);
|
|
}
|
|
|
|
public virtual XMLDocument getValue(string aTag)
|
|
{
|
|
XMLDocument tXMLDocument = null;
|
|
int tStartIndex = this.iXMLString.IndexOf("<" + aTag.Trim() + ">");
|
|
int tEndIndex = this.iXMLString.IndexOf("</" + aTag.Trim() + ">");
|
|
if (((tStartIndex >= 0) && (tEndIndex >= 0)) && (tStartIndex < tEndIndex)) {
|
|
tXMLDocument = new XMLDocument(this.iXMLString.Substring((tStartIndex + aTag.Length) + 2, tEndIndex - ((tStartIndex + aTag.Length) + 2)));
|
|
}
|
|
return tXMLDocument;
|
|
}
|
|
|
|
public virtual ArrayList getValueArrayList(string aTag)
|
|
{
|
|
string tXMLString = this.iXMLString;
|
|
ArrayList tValues = new ArrayList();
|
|
while (true) {
|
|
XMLDocument tXMLDocument = null;
|
|
int tStartIndex = tXMLString.IndexOf("<" + aTag.Trim() + ">");
|
|
int tEndIndex = tXMLString.IndexOf("</" + aTag.Trim() + ">");
|
|
if (((tStartIndex == -1) || (tEndIndex == -1)) || (tStartIndex > tEndIndex)) {
|
|
return tValues;
|
|
}
|
|
tXMLDocument = new XMLDocument(tXMLString.Substring((tStartIndex + aTag.Length) + 2, tEndIndex - ((tStartIndex + aTag.Length) + 2)));
|
|
tValues.Add(tXMLDocument);
|
|
tXMLString = tXMLString.Substring(tEndIndex + 1);
|
|
}
|
|
}
|
|
|
|
public virtual string getValueNoNull(string aTag)
|
|
{
|
|
string tValue = "";
|
|
XMLDocument tXML = this.getValue(aTag);
|
|
if (tXML != null) {
|
|
tValue = tXML.ToString();
|
|
}
|
|
return tValue;
|
|
}
|
|
|
|
public XMLDocument init(string aXMLString)
|
|
{
|
|
this.iXMLString = aXMLString;
|
|
return this;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return this.iXMLString;
|
|
}
|
|
}
|
|
}
|