jo lu

jo lu

  • NA
  • 3
  • 0

Read XML document Like LN1, FN1, L1, P1 HELP!!!!!!!!!! SEE XML FILE

Jan 9 2010 8:36 PM
- <User>
  <FirstName1>fn1</FirstName1>
  <MiddleName1>mn1</MiddleName1>
  <LastName1>ln1</LastName1>
  <DisplayName1>fn1 mn1 ln1</DisplayName1>
  <Login1>AF4073</Login1>
  <Password1>5F4DCC3B5AA765D61D8327DEB882CF99</Password1>
  <FirstName2>fn2</FirstName2>
  <MiddleName2>mn2</MiddleName2>
  <LastName2>ln2</LastName2>
  <DisplayName2>fn2 mn2 ln2</DisplayName2>
  <Login2>AC4070</Login2>
  <Password2>5F4DCC3B5AA765D61D8327DEB882CF99</Password2>
  <FirstName3>fn3</FirstName3>
  <MiddleName3>mn3</MiddleName3>
  <LastName3>ln3</LastName3>
  <DisplayName3>fn3 mn3 ln3</DisplayName3>
  <Login3>AJ4077</Login3>
  <Password3>5F4DCC3B5AA765D61D8327DEB882CF99</Password3>
  <FirstName4>fn4</FirstName4>
  <MiddleName4>mn4</MiddleName4>
  <LastName4>ln4</LastName4>
  <DisplayName4>fn4 mn4 ln4</DisplayName4>
  <Login4>AE4072</Login4>
  <Password4>0CC175B9C0F1B6A831C399E269772661</Password4>
  <FirstName5>fn5</FirstName5>
  <MiddleName5>mn5</MiddleName5>
  <LastName5>ln5</LastName5>
  <DisplayName5>fn5 mn5 ln5</DisplayName5>
  <Login5>AF4073</Login5>
  <Password5>9E3669D19B675BD57058FD4664205D2A</Password5>
  <FirstName6 />
  <MiddleName6 />
  <LastName6 />
  <DisplayName6 />
  <Login6 />
  <Password6 />
  <FirstName7 />
  <MiddleName7 />
  <LastName7 />
  <DisplayName7 />
  <Login7 />
  <Password7 />
  <FirstName8 />
  <MiddleName8 />
  <LastName8 />
  <DisplayName8 />
  <Login8 />
  <Password8 />
  <FirstName9 />
  <MiddleName9 />
  <LastName9 />
  <DisplayName9 />
  <Login9 />
  <Password9 />
  <FirstName10 />
  <MiddleName10 />
  <LastName10 />
  <DisplayName10 />
  <Login10 />
  <Password10 />
  <FirstName11 />
  <MiddleName11 />
  <LastName11 />
  <DisplayName11 />
  <Login11 />
  <Password11 />
  <ArchiveStatus />
- <ROLES>
  <Role>Student</Role>
  </ROLES>
  </User>
 
 
=========================================

using
System;
using
System.Web;
using
System.Collections;
using
System.Web.Services;
using
System.Web.Services.Protocols;
using
System.DirectoryServices;
using
System.Configuration;
using
System.Xml;
using
System.Security.Principal;
using
System.Collections.Generic;
using
AcDataAccess;
using
System.Text;
using
System.Data;
using
System.IO;
using
System.Data.SqlClient;
using
System.Globalization;
using
System.Threading;
///
<summary>
///
Summary description for VCMMNETPersonInfo
///
</summary>
[
WebService(Namespace = "http://localhost/")]
[
WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]

public
class VCMMNETPersonInfo : System.Web.Services.WebService
{
public VCMMNETPersonInfo()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[
WebMethod(true, Description = "This method adds students En Masse, Owner: Moses Ssemukutu")]
public XmlDocument AddUsers(string queryXml)
{
try
{
VCMMNETPersonDocument person = new VCMMNETPersonDocument();
XmlDocument xmlDocument = new XmlDocument();
string strMsg = "";
string actionType = "";
bool flgNew = false;
xmlDocument.LoadXml(queryXml);
string docId = Util.GetXPath(xmlDocument, "query/documentID");
string documentXml = Util.GetInnerXML(xmlDocument, "query/documentXml");
if (docId == null) docId = "";
person.DocID = docId;
if (docId == "")
{
if (!person.CanCreate)
throw new Exception("You do not have permission to create a " + person.Type + " document.");
flgNew =
true;
}
else
{
if (!person.CanEdit)
throw new Exception("You do not have permission to edit a " + person.Type + " document.");
//iitialize from db record
person.VCMMNETLoadObject();
}
//update from xml body
person.VCMMNETLoadObject(documentXml);
}
catch (Exception ex)
{
AcXmlClasses.AddLogEntry("Error when calling AddUsers: " + ex.ToString(), 1);
return AcException.GetXmlException(ex);
}
}
}
===============================================
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Xml;
using
System.Text;
using
AcDataAccess;
using
System.Collections.Generic;
using
System.IO;
using
System.Xml.Xsl;
using
System.Globalization;
using
System.Threading;
///
<summary>
///
Summary description for VCMMNETPersonDocument
///
</summary>
public
class VCMMNETPersonDocument : VCMMNETAcDocument
{
public VCMMNETPersonDocument()
{
this.Type = "Person Document";
this.TableName = "DOCUMENTS_PEOPLE";
this.IdColumnName = "PersonId";
}

#region
Properties
string firstname = "";
string lastname = "";
string middlename = "";
string displayname = "";
string archivestatus = "";
string loginname = "";
string password = "";
string roles = "";
string xmlbody = "";
public string FirstName { get { return firstname; } set { firstname = value; } }
public string MiddleName { get { return middlename; } set { middlename = value; } }
public string LastName { get { return lastname; } set { lastname = value; } }
public string DisplayName { get { return displayname; } set { displayname = value; } }
public string ArchiveStatus { get { return archivestatus; } set { archivestatus = value; } }
public string LoginName { get { return loginname; } set { loginname = value; } }
public string Password { get { return password; } set { password = value; } }
public string Roles { get { return roles; } set { roles = value; } }
public string XMLBody { get { return xmlbody; } set { xmlbody = value; } }
#endregion

internal override void VCMMNETLoadObject(string documentXml)
{
XmlDocument xmlBody = new XmlDocument();
if (documentXml == "")
{
throw new Exception("No parameter passed for add person Web Service");
}
try
{
xmlBody.LoadXml(documentXml);
}
catch (Exception)
{
throw new Exception("Error reading query string passed to add person Web Service. It may not be a wellformed XML.");
}
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
FirstName =
Util.GetXPath(xmlBody, "//FirstName");
MiddleName =
Util.GetXPath(xmlBody, "//MiddleName");
LastName =
Util.GetXPath(xmlBody, "//LastName");
DisplayName =
Util.GetXPath(xmlBody, "//DisplayName");
LoginName =
Util.GetXPath(xmlBody, "//LoginName");
Password =
Util.GetXPath(xmlBody, "//Password");
XMLBody = GetXmlBody(xmlBody);
Thread.CurrentThread.CurrentCulture = currentCulture;
}
private Boolean paramExists(XmlDocument paramDoc, String paramName)
{
Boolean ReturnVal = false;
try
{
String tmpVal = AcXmlClasses.GetInnerXML(paramDoc, "//" + paramName);
ReturnVal =
true;
}
catch
{
ReturnVal =
false;
}
return ReturnVal;
}
private String ReadParam(XmlDocument paramDoc, String paramName)
{
String ReturnVal = "";
try
{
ReturnVal =
AcXmlClasses.GetInnerXML(paramDoc, "//" + paramName);
}
catch { }
return ReturnVal;
}
internal override int Save()
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
XmlDocument xmlBody = new XmlDocument();
try
{

if (ArchiveStatus == "")
{
ArchiveStatus =
"False";
}
Dictionary<string, string> fields = new Dictionary<string, string>();
fields.Add(
"FirstName", Util.Unstrip(firstname));
fields.Add(
"MiddleName", Util.Unstrip(middlename));
fields.Add(
"LastName", Util.Unstrip(lastname));
fields.Add(
"DisplayName", Util.Unstrip(displayname));
fields.Add(
"ArchiveStatus", Util.Unstrip(archivestatus));
fields.Add(
"LoginName", Util.Unstrip(loginname));
fields.Add(
"Password", Util.Unstrip(password));
xmlBody.LoadXml(XMLBody);
fields.Add(
"XMLBody", GetXmlBody(xmlBody));
Person person = Util.GetCurrentPerson();
string CurrentUser = person.DisplayName;
int tmpreturn = -1;
if ((DocID == "") || (DocID == null))
{
if (!CanCreate)
throw new Exception("You do not have permission to create a new person.");
string numberOfDupes = Selecter.SelectScalar("select count(*) from DOCUMENTS_People where isnull(ArchiveStatus,0) != 1 and displayname = '" + Util.Unstrip(DisplayName).Replace("'", "''") + "'").ToString();
//string numberOfDupes = Selecter.SelectScalar("select count(*) from DOCUMENTS_People where displayname = '" + Util.Unstrip(DisplayName).Replace("'", "''") + "'").ToString();
if (numberOfDupes != "0")
{
throw new Exception("An active or archived person with this display name already exists.");
}
fields.Add(
"CreatedBy", CurrentUser);
Inserter inserter = new Inserter("Documents_People");
foreach (string key in fields.Keys)
{
inserter[key] = fields[key].ToString();
}
tmpreturn = inserter.Insert();
DocID = tmpreturn.ToString();
}
else
{
if (!CanEdit)
throw new Exception("You do not have permission to edit a person.");
fields.Add(
"ModifiedBy", CurrentUser);
Updater updater = new Updater("Documents_People", "PersonId", Int32.Parse(DocID));
foreach (string key in fields.Keys)
{
updater[key] = fields[key].ToString();
}
tmpreturn = updater.Update();
}
return tmpreturn;
}
catch (Exception e)
{
throw new Exception("Error saving person info: " + e.Message);
}
}
internal override void VCMMNETLoadObject()
{
try
{
string query = "Select * from DOCUMENTS_PEOPLE where PersonId = " + this.DocID;
AcDataAccess.
Selecter selecter = new AcDataAccess.Selecter();
using (IDataReader dr = selecter.select(query))
{
dr.Read();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(dr[
"XmlBody"].ToString());
ArchiveStatus = dr[
"ArchiveStatus"].ToString();
VCMMNETLoadObject(xmlDocument.InnerXml);
}
}
catch { }
}
string GetXmlBody(XmlDocument xmlBody)
{
StringBuilder sb = new StringBuilder();
sb.Append(
"<PERSON>");
sb.Append(
"<FirstName>" + Util.FullStrip(FirstName) + "</FirstName>");
sb.Append(
"<MiddleName>" + Util.FullStrip(MiddleName) + "</MiddleName>");
sb.Append(
"<LastName>" + Util.FullStrip(LastName) + "</LastName>");
sb.Append(
"<DisplayName>" + Util.FullStrip(DisplayName) + "</DisplayName>");
sb.Append(
"<LoginName>" + Util.FullStrip(LoginName) + "</LoginName>");
sb.Append(
"<Password>" + Util.FullStrip(Password) + "</Password>");
sb.Append(
"<ArchiveStatus>" + ArchiveStatus + "</ArchiveStatus>");
sb.Append(
"</PERSON>");
return sb.ToString();
}
}

Answers (1)