Knowledge Base Nr: 00331 setgetxml.java - http://www.swe-kaiser.de
Downloads:
Java: GWT: einfache xml string funktionen
public static String GetXMLTag(String sText, String sTag)
{
String sXMLText = "";
int p1 = sText.indexOf("<" + sTag + ">");
int p2 = sText.indexOf("</" + sTag + ">");
if ((p1 >= 0) && (p2 >= 0))
{
p1 += sTag.length()+2;
sXMLText = sText.substring(p1, p2).trim();
}
return sXMLText;
}
public static String SetXMLTag(String sText, String sTag, String sValue)
{
int p1 = sText.indexOf("<" + sTag + ">");
int p2 = sText.indexOf("</" + sTag + ">");
if ((p1 >= 0) && (p2 >= 0))
{
p1 += sTag.length()+2;
String s1 = sText.substring(0, p1).trim();
String s2 = sText.substring(p2).trim();
sText = s1 + sValue + s2;
return sText;
}
else if ((p1 < 0) && (p2 < 0))
{
sText += "<" + sTag + ">" + sValue + "</" + sTag + ">";
return sText;
}
return "SetXMLTag() - Syntax Errors: " + sText;
}