EDN Admin
Well-known member
Im trying to edit an XML doc that is a template order form, I will then serialize the edited doc and send to a webservice.
I can replace the FirstChild with my <FaceAmt>350000</FaceAmt> to prove that some of what Im doing works, but that results in replacing the entire <UserAuthRequest> and NOT AT ALL WHAT I WANT TO DO...
I had an earlier issue that I solved the poor mans way, the TXLife root element contains a few namespaces, which caused my old-Node that I named nodeToEdit to always be null, adding the ns enabled it to populate but now my <FaceAmt>250000</FaceAmt>
was now <FaceAmt xmlns=" http://ACORD.org/Standards/Life/2%22 http://ACORD.org/Standards/Life/2" >250000</FaceAmt>, so it got me no closer, so I abondoned that for now expecting that once I was able to get the replaceChild
working Id add back the namespaces to <TXLife>.
...c# code
<pre lang="x-c# using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Xml;
using System.Xml.XPath;
public partial class ParamedAdmin_v2 : System.Web.UI.Page
{
#region Properties...
// XML Template Path
private static string xmltemplatepath;
public static string XMLTemplatePath
{
get {
if ((xmltemplatepath != null) != false)
return xmltemplatepath;
else
xmltemplatepath = "http://localhost/smm_v1/xml_resource/";
return xmltemplatepath;
}
}
// XML Template Filename
private static string xmltemplatefile;
public static string XMLTemplateFile
{
get {
if ((xmltemplatefile != null) != false)
return xmltemplatefile;
else
xmltemplatefile = "txlife_smm.xml";
return xmltemplatefile;
}
}
// Load the XML Template using DOM
private static XmlDocument xmldoc;
public static XmlDocument XMLDoc
{
get {
if ((xmldoc != null) != false)
return xmldoc;
else
xmldoc = new XmlDocument();
xmldoc.Load(XMLTemplatePath + XMLTemplateFile);
return xmldoc;
}
set { xmldoc = value; }
}
#endregion
#region Testing somethings...
static Boolean HeyNow()
{
// XPath, XPathNavigator, Reader , SelectSingleNode, ReplaceChild
XmlTextReader reader = new XmlTextReader(XMLTemplatePath + XMLTemplateFile);
XMLDoc.Load(reader);
reader.Close();
XmlElement root = XMLDoc.DocumentElement;
//XmlNamespaceManager ns = new XmlNamespaceManager(XMLDoc.NameTable);
//ns.AddNamespace("SMM", "http://ACORD.org/Standards/Life/2");
//string xpres = "descendant::SMM:FaceAmt";
//XmlNode nodeToEdit = root.SelectSingleNode(xpres, ns);
string xpres = "descendant::FaceAmt";
XmlNode nodeToEdit = root.SelectSingleNode(xpres);
XmlNode idNodeToEdit = XMLDoc.GetElementById("uPolAmount");
XmlElement newNode = XMLDoc.CreateElement("FaceAmt");
newNode.InnerText = "350000";
root.ReplaceChild(newNode, nodeToEdit);
XMLDoc.Save("c:\inetpub\wwwroot\SMM_v1\TestFiles\Test01.xml");
return true;
}
#endregion
# region Page Events
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
HeyNow();
}
}
#endregion
}
[/code]
<pre lang="x-xml <TXLife>
<UserAuthRequest>
<UserLoginName>eabdulhamid</UserLoginName>
<UserPswd>
<CryptType>NONE</CryptType>
<Pswd>qwerty</Pswd>
</UserPswd>
<VendorApp>
<VendorName VendorCode="148 Protective Life</VendorName>
<AppName>VendorServices</AppName>
<AppVer>1.0</AppVer>
</VendorApp>
</UserAuthRequest>
<TXLifeRequest>
<TransRefGUID>2244FB72-2377-FD01-2473-4685B5D12EDE</TransRefGUID>
<TransType tc="121 General Requirement Order Request</TransType>
<TransExeDate>2010-04-08</TransExeDate>
<TransExeTime>16:43:02</TransExeTime>
<TransMode tc="2 Original</TransMode>
<NoResponseOK tc="0 False</NoResponseOK>
<TestIndicator tc="0 False</TestIndicator>
<OLifE>
<Holding id="Holding_167392
<HoldingTypeCode tc="2 Policy</HoldingTypeCode>
<HoldingStatus tc="3 Proposed</HoldingStatus>
<HoldingForm tc="1 Individual</HoldingForm>
<Policy id="Pending_Policy_TT5SMM777" CarrierPartyID="CarrierParty_167393
<PolNumber>TT5SMM777</PolNumber>
<LineOfBusiness tc="1 Life</LineOfBusiness>
<ProductType tc="2 Term Life</ProductType>
<PlanName>ValueChoice Term-30</PlanName>
<PolicyStatus tc="12 Proposed</PolicyStatus>
<Life>
<FaceAmt>250000</FaceAmt>
</Life>
</Policy>
</Holding>
<Party id="InsuredParty_5293884
<PartyTypeCode tc="1 Person</PartyTypeCode>
<GovtID>123121234</GovtID>
<GovtIDTC tc="1 Social Security Number US</GovtIDTC>
<Person>
<FirstName>Superior</FirstName>
<LastName>Test</LastName>
<Gender tc="1 Male</Gender>
<BirthDate>1965-01-01</BirthDate>
<DriversLicenseNum>none</DriversLicenseNum>
<DriversLicenseState tc="17 IL</DriversLicenseState>
</Person>
<Address>
<AddressTypeCode tc="1 Residence</AddressTypeCode>
<Line1>123 Superior Street</Line1>
<City>City</City>
<AddressStateTC tc="17 IL</AddressStateTC>
<Zip>89089</Zip>
</Address>
<Phone>
<PhoneTypeCode tc="1 Home</PhoneTypeCode>
<AreaCode>890</AreaCode>
<DialNumber>8908908</DialNumber>
</Phone>
</Party>
<Party id="CarrierParty_167393
<PartyTypeCode tc="2 Organization</PartyTypeCode>
<FullName>PLICO</FullName>
<Organization>
<OrgForm tc="23 Company</OrgForm>
</Organization>
</Party>
<Party id="RequestorContactParty_167395
<PartyTypeCode tc="1 Person</PartyTypeCode>
<FullName>TeleLife</FullName>
<Person />
<Phone>
<PhoneTypeCode tc="2 Business</PhoneTypeCode>
<AreaCode>888</AreaCode>
<DialNumber>8006608</DialNumber>
<Ext>Opt. 2</Ext>
</Phone>
</Party>
<Party id="AGT1_0000424001_1
<PartyTypeCode tc="1 Person</PartyTypeCode>
<GovtID>424488015</GovtID>
<Person>
<LastName>SMITH, GEORGE</LastName>
</Person>
<Producer>
<CarrierAppointment>
<CompanyProducerID>0000424001</CompanyProducerID>
</CarrierAppointment>
</Producer>
</Party>
<Relation id="Holding_167392_To_InsuredParty_5293884" OriginatingObjectID="Holding_167392" RelatedObjectID="InsuredParty_5293884
<OriginatingObjectType tc="4 Holding</OriginatingObjectType>
<RelatedObjectType tc="6 Party</RelatedObjectType>
<RelationRoleCode tc="32 Insured</RelationRoleCode>
</Relation>
<Relation id="Holding_To_WritingAgent_AGT1_0000424001_1" OriginatingObjectID="Holding_167392" RelatedObjectID="AGT1_0000424001_1
<OriginatingObjectType tc="4 Holding</OriginatingObjectType>
<RelatedObjectType tc="6 Party</RelatedObjectType>
<RelationRoleCode tc="52 Writing Agent</RelationRoleCode>
</Relation>
</OLifE>
</TXLifeRequest>
</TXLife>[/code]
<br/>
<
JeffP...
View the full article
I can replace the FirstChild with my <FaceAmt>350000</FaceAmt> to prove that some of what Im doing works, but that results in replacing the entire <UserAuthRequest> and NOT AT ALL WHAT I WANT TO DO...
I had an earlier issue that I solved the poor mans way, the TXLife root element contains a few namespaces, which caused my old-Node that I named nodeToEdit to always be null, adding the ns enabled it to populate but now my <FaceAmt>250000</FaceAmt>
was now <FaceAmt xmlns=" http://ACORD.org/Standards/Life/2%22 http://ACORD.org/Standards/Life/2" >250000</FaceAmt>, so it got me no closer, so I abondoned that for now expecting that once I was able to get the replaceChild
working Id add back the namespaces to <TXLife>.
...c# code
<pre lang="x-c# using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Xml;
using System.Xml.XPath;
public partial class ParamedAdmin_v2 : System.Web.UI.Page
{
#region Properties...
// XML Template Path
private static string xmltemplatepath;
public static string XMLTemplatePath
{
get {
if ((xmltemplatepath != null) != false)
return xmltemplatepath;
else
xmltemplatepath = "http://localhost/smm_v1/xml_resource/";
return xmltemplatepath;
}
}
// XML Template Filename
private static string xmltemplatefile;
public static string XMLTemplateFile
{
get {
if ((xmltemplatefile != null) != false)
return xmltemplatefile;
else
xmltemplatefile = "txlife_smm.xml";
return xmltemplatefile;
}
}
// Load the XML Template using DOM
private static XmlDocument xmldoc;
public static XmlDocument XMLDoc
{
get {
if ((xmldoc != null) != false)
return xmldoc;
else
xmldoc = new XmlDocument();
xmldoc.Load(XMLTemplatePath + XMLTemplateFile);
return xmldoc;
}
set { xmldoc = value; }
}
#endregion
#region Testing somethings...
static Boolean HeyNow()
{
// XPath, XPathNavigator, Reader , SelectSingleNode, ReplaceChild
XmlTextReader reader = new XmlTextReader(XMLTemplatePath + XMLTemplateFile);
XMLDoc.Load(reader);
reader.Close();
XmlElement root = XMLDoc.DocumentElement;
//XmlNamespaceManager ns = new XmlNamespaceManager(XMLDoc.NameTable);
//ns.AddNamespace("SMM", "http://ACORD.org/Standards/Life/2");
//string xpres = "descendant::SMM:FaceAmt";
//XmlNode nodeToEdit = root.SelectSingleNode(xpres, ns);
string xpres = "descendant::FaceAmt";
XmlNode nodeToEdit = root.SelectSingleNode(xpres);
XmlNode idNodeToEdit = XMLDoc.GetElementById("uPolAmount");
XmlElement newNode = XMLDoc.CreateElement("FaceAmt");
newNode.InnerText = "350000";
root.ReplaceChild(newNode, nodeToEdit);
XMLDoc.Save("c:\inetpub\wwwroot\SMM_v1\TestFiles\Test01.xml");
return true;
}
#endregion
# region Page Events
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
HeyNow();
}
}
#endregion
}
[/code]
<pre lang="x-xml <TXLife>
<UserAuthRequest>
<UserLoginName>eabdulhamid</UserLoginName>
<UserPswd>
<CryptType>NONE</CryptType>
<Pswd>qwerty</Pswd>
</UserPswd>
<VendorApp>
<VendorName VendorCode="148 Protective Life</VendorName>
<AppName>VendorServices</AppName>
<AppVer>1.0</AppVer>
</VendorApp>
</UserAuthRequest>
<TXLifeRequest>
<TransRefGUID>2244FB72-2377-FD01-2473-4685B5D12EDE</TransRefGUID>
<TransType tc="121 General Requirement Order Request</TransType>
<TransExeDate>2010-04-08</TransExeDate>
<TransExeTime>16:43:02</TransExeTime>
<TransMode tc="2 Original</TransMode>
<NoResponseOK tc="0 False</NoResponseOK>
<TestIndicator tc="0 False</TestIndicator>
<OLifE>
<Holding id="Holding_167392
<HoldingTypeCode tc="2 Policy</HoldingTypeCode>
<HoldingStatus tc="3 Proposed</HoldingStatus>
<HoldingForm tc="1 Individual</HoldingForm>
<Policy id="Pending_Policy_TT5SMM777" CarrierPartyID="CarrierParty_167393
<PolNumber>TT5SMM777</PolNumber>
<LineOfBusiness tc="1 Life</LineOfBusiness>
<ProductType tc="2 Term Life</ProductType>
<PlanName>ValueChoice Term-30</PlanName>
<PolicyStatus tc="12 Proposed</PolicyStatus>
<Life>
<FaceAmt>250000</FaceAmt>
</Life>
</Policy>
</Holding>
<Party id="InsuredParty_5293884
<PartyTypeCode tc="1 Person</PartyTypeCode>
<GovtID>123121234</GovtID>
<GovtIDTC tc="1 Social Security Number US</GovtIDTC>
<Person>
<FirstName>Superior</FirstName>
<LastName>Test</LastName>
<Gender tc="1 Male</Gender>
<BirthDate>1965-01-01</BirthDate>
<DriversLicenseNum>none</DriversLicenseNum>
<DriversLicenseState tc="17 IL</DriversLicenseState>
</Person>
<Address>
<AddressTypeCode tc="1 Residence</AddressTypeCode>
<Line1>123 Superior Street</Line1>
<City>City</City>
<AddressStateTC tc="17 IL</AddressStateTC>
<Zip>89089</Zip>
</Address>
<Phone>
<PhoneTypeCode tc="1 Home</PhoneTypeCode>
<AreaCode>890</AreaCode>
<DialNumber>8908908</DialNumber>
</Phone>
</Party>
<Party id="CarrierParty_167393
<PartyTypeCode tc="2 Organization</PartyTypeCode>
<FullName>PLICO</FullName>
<Organization>
<OrgForm tc="23 Company</OrgForm>
</Organization>
</Party>
<Party id="RequestorContactParty_167395
<PartyTypeCode tc="1 Person</PartyTypeCode>
<FullName>TeleLife</FullName>
<Person />
<Phone>
<PhoneTypeCode tc="2 Business</PhoneTypeCode>
<AreaCode>888</AreaCode>
<DialNumber>8006608</DialNumber>
<Ext>Opt. 2</Ext>
</Phone>
</Party>
<Party id="AGT1_0000424001_1
<PartyTypeCode tc="1 Person</PartyTypeCode>
<GovtID>424488015</GovtID>
<Person>
<LastName>SMITH, GEORGE</LastName>
</Person>
<Producer>
<CarrierAppointment>
<CompanyProducerID>0000424001</CompanyProducerID>
</CarrierAppointment>
</Producer>
</Party>
<Relation id="Holding_167392_To_InsuredParty_5293884" OriginatingObjectID="Holding_167392" RelatedObjectID="InsuredParty_5293884
<OriginatingObjectType tc="4 Holding</OriginatingObjectType>
<RelatedObjectType tc="6 Party</RelatedObjectType>
<RelationRoleCode tc="32 Insured</RelationRoleCode>
</Relation>
<Relation id="Holding_To_WritingAgent_AGT1_0000424001_1" OriginatingObjectID="Holding_167392" RelatedObjectID="AGT1_0000424001_1
<OriginatingObjectType tc="4 Holding</OriginatingObjectType>
<RelatedObjectType tc="6 Party</RelatedObjectType>
<RelationRoleCode tc="52 Writing Agent</RelationRoleCode>
</Relation>
</OLifE>
</TXLifeRequest>
</TXLife>[/code]
<br/>
<
JeffP...
View the full article