Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8348743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:46:59+00:00 2026-06-09T07:46:59+00:00

The following function does not return the value of the node that I want,

  • 0

The following function does not return the value of the node that I want, which is “CompanyPolicyId”. I have tried so many things and I still cannot get it to work. Anyone know what might be the issue?

 public void getpolicy(string rootURL, string policyNumber)
        {
            string basePolicyNumber = policyNumber.Remove(policyNumber.Length - 2);
            basePolicyNumber = basePolicyNumber + "00";

            using (WebClient client = new WebClient())
            {
                NetworkCredential credentials = new NetworkCredential();
                credentials.UserName = AppVars.Username;
                credentials.Password = AppVars.Password;
                client.Credentials = credentials;

                try
                {
                    XmlDocument doc = new XmlDocument();

                    doc.LoadXml(client.DownloadString(rootURL + basePolicyNumber));
                    XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                    mgr.AddNamespace("zzzlocal", "http://com.zzz100.policy.data.local");

                    // Select the Identifier node with a 'name' attribute having an 'id' value
                    var node = doc.DocumentElement.SelectSingleNode("/InsurancePolicy/Indentifiers/Identifier[@name='CompanyPolicyId']", mgr);
                    if (node != null && node.Attributes["value"] != null)
                    {
                        // Pick out the 'value' attribute's value
                        var val = node.Attributes["value"].Value;

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            } 

Here’s the XML document:

<InsurancePolicy xmlns:zzzlocal="com.zzz100.policy.data.local" schemaVersion="2.7" variant="multiterm">
<Identifiers>
<Identifier name="VendorPolicyId" value="AAAA"/>
<Identifier name="CompanyPolicyId" value="BBBB"/>
<Identifier name="QuoteNumber" value="CCCC"/>
<Identifier name="pxServerIndex" value="DDDD"/>
<Identifier name="PolicyID" value="EEEE"/>
</Identifiers>
</InsurancePolicy>

I’ve been trying to fix this problem for the last 6 hours. Honestly, this sucks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:47:00+00:00Added an answer on June 9, 2026 at 7:47 am

    Try to use this

    //Identifier[@name='CompanyPolicyId']"
    

    or a different approach below

    XElement rootElement = XElement.Load(<url here>);
    string targetValue =
      (string)rootElement.Elements("Identifier")
      .Single(e => (string)e.Attribute("name") == "CompanyPolicyId")
      .Attribute("value");
    

    This assumes that you want to be able to target one of the Identifier nodes by name, and that you are sure that there will be an element WITH that name. If that is not true, then the .Single call will throw an Exception if that node is not found.

    If you needed to use credentials and wanted to use a WebClient, then you could use the following:
    (Note, I have done no exception handling, checking for stream availability, or otherwise disposed/closed the streams, just an example of how to get it to “work”)

    string uri = "> url here! <";
    System.Net.WebClient wc = new System.Net.WebClient();
    StreamReader sr = new StreamReader(wc.OpenRead(uri));
    string xml = sr.ReadToEnd();
    XElement rootElement = XElement.Parse(xml);
    string targetValue =
      (string)rootElement.Elements("Identifier")
      .Single(e => (string)e.Attribute("name") == "CompanyPolicyId")
      .Attribute("value");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that does string splitting: on splitText(aString, delimiter) set retVal
Say I have a function that does the following in Vb.net For i as
I have the following function which compares the first column value in two 2D
Function calculate_attribute does not return a value; it only works through side effects. Often
the following function does not work as I thought it should have. For some
I'm getting crazy with this IE 7... ==> hhttp://neu.emergent-innovation.com/ Why does following function not
The following code does not submit the input values: $('.button').live('click', function() { var date
This is a Function that does the following: Create a random Token with 8
I'm trying to write a function that does the following: takes an array of
I have the following Javascript function that makes a call to an Asp.Net WebMethod

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.