locked
deserialize from a string RRS feed

  • Question

  • User-2012457684 posted

     Now that I know how to read the document I am getting an error when trying to load the XML string that is received from the web service.

    This is the error 

    System.InvalidOperationException There is an error in XML document (1, 40).
    
    Inner Exception  
    InvalidOperationException: <Results xmlns=''> was not expected.

    This is the XML document that is coming in from the web service  (results string in below code)

    <?xml version=\"1.0\" encoding=\"UTF-8\"?><Results><HireAbilityXMLResults id=\"2912536341131\"  usageLimitType=\"allocation\" usageLimit=\"5003\" currentUsage=\"27\" remainingUsage=\"4976\" accountValidThrough=\"09-15-2021\"><Resume xmlns=\"http://ns.hr-xml.org/2007-04-15\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xml:lang=\"EN\" xsi:schemaLocation=\"https://s3.amazonaws.com/Build_2_5/HR-XML-2_5/SEP/Resume.xsd\"><ResumeId><IdValue/></ResumeId><StructuredXMLResume><ContactInfo><PersonName><FormattedName>John E Doe</FormattedName><GivenName>John</GivenName><MiddleName>E</MiddleName><FamilyName>Doe</FamilyName></PersonName><ContactMethod><PostalAddress><CountryCode>US</CountryCode><PostalCode>1111</PostalCode><Region>IA</Region><Municipality>Sioux City</Municipality><DeliveryAddress><AddressLine>1234 Main St.</AddressLine></DeliveryAddress></PostalAddress></ContactMethod><ContactMethod><Use>personal</Use><Location>home</Location><WhenAvailable>unknown</WhenAvailable><Telephone><FormattedNumber>(712)123-4567</FormattedNumber><InternationalCountryCode>1</InternationalCountryCode><AreaCityCode>712</AreaCityCode><SubscriberNumber>123-4567</SubscriberNumber></Telephone></ContactMethod><ContactMethod><Use>personal</Use><Location>onPerson</Location><WhenAvailable>anytime</WhenAvailable><Mobile><FormattedNumber>(712)555-1234</FormattedNumber><InternationalCountryCode>1</InternationalCountryCode><AreaCityCode>712</AreaCityCode><SubscriberNumber>555-1234</SubscriberNumber></Mobile></ContactMethod><ContactMethod><InternetEmailAddress>John.doe@deermail.com</InternetEmailAddress></ContactMethod></ContactInfo><ExecutiveSummary> * 5+ years of successful customer service experience. * Skilled at communication with internal and external customers as evidence by outstanding satisfaction surveys and performance reviews. * Competent in use of technology to deliver service: automated dialers, sales and service databases, hands-free telephonic devices.</ExecutiveSummary><EmploymentHistory><EmployerOrg><EmployerOrgName>Ring-E-Ding Worldwide</EmployerOrgName><JobType/><PositionHistory><Title>Customer Service Representative</Title><OrgName><OrganizationName/></OrgName><OrgInfo><PositionLocation><CountryCode>US</CountryCode><Region>IA</Region><Municipality>Sioux City</Municipality></PositionLocation></OrgInfo><OrgIndustry primaryIndicator=\"true\"><IndustryDescription>customer service</IndustryDescription></OrgIndustry><Description>Provide world-class customer service support for gamin system users via telephone and live chat formats. * Assist customers with set-up of new devices and troubleshooting of problems. * Utilize diagnostic steps to determine prompt identification of issues and solutions. * Use de-escalation techniques to diffuse customer frustrations. * Offer appropriate services and products to enhance end-user experience. * Document all interactions thoroughly and timely to streamline future interactions between customer and call-center staff.</Description><StartDate><AnyDate>2013-04-01</AnyDate></StartDate><EndDate><AnyDate>current</AnyDate></EndDate></PositionHistory><UserArea><employerNameConfidenceRating>50</employerNameConfidenceRating><jobTitleConfidenceRating>100</jobTitleConfidenceRating><startDateConfidenceRating>100</startDateConfidenceRating><endDateConfidenceRating>100</endDateConfidenceRating><datesConfidenceRating>100</datesConfidenceRating><descriptionConfidenceRating>100</descriptionConfidenceRating><positionConfidenceRating>87</positionConfidenceRating></UserArea></EmployerOrg><EmployerOrg><EmployerOrgName>Eddie Bow-wow</EmployerOrgName><JobType/><PositionHistory><OrgName><OrganizationName/></OrgName><OrgInfo><PositionLocation><CountryCode>US</CountryCode><Region>IA</Region><Municipality>Sioux City</Municipality></PositionLocation></OrgInfo><OrgIndustry primaryIndicator=\"true\"><IndustryDescription>sales</IndustryDescription></OrgIndustry><Description>Assisted dogs and their humans with selection and purchase of quality of life products such as: bedding, feeding, safety, and exercise items. * Maintained a high level of product knowledge in order to suggest alternatives and compare products side-by-side. * Participated in company sales incentive programs and consistently finished in the top 3 Associates district-wide. * Offered appropriate resolutions to customer concerns in order to assure return business. * Recipient of \"Best of Bow-wow\" award for 38 store district.</Description><StartDate><AnyDate>2007-01-01</AnyDate></StartDate><EndDate><AnyDate>2007-01-01</AnyDate></EndDate></PositionHistory><UserArea><employerNameConfidenceRating>50</employerNameConfidenceRating><jobTitleConfidenceRating>0</jobTitleConfidenceRating><startDateConfidenceRating>100</startDateConfidenceRating><endDateConfidenceRating>100</endDateConfidenceRating><datesConfidenceRating>100</datesConfidenceRating><descriptionConfidenceRating>100</descriptionConfidenceRating><positionConfidenceRating>62</positionConfidenceRating></UserArea></EmployerOrg><EmployerOrg><EmployerOrgName>Bigger Heavy Stuff Inc.</EmployerOrgName><JobType/><PositionHistory><OrgName><OrganizationName/></OrgName><OrgInfo><PositionLocation><CountryCode>US</CountryCode><Region>IA</Region><Municipality>Sioux City</Municipality></PositionLocation></OrgInfo><Description>Performed warehouse labor at a Fortune 500 manufacturer of computing devices. * Tagged and labeled containers to identify contents and assure accurate delivery to customer. * Read and interpreted work orders to triage each day's activities * Determined work assignments and equipment needs to maintain efficient use of human and material resources. * Loaded and unloaded materials on semi-trailers using forklifts and pallet jacks.</Description><StartDate><AnyDate>2007-01-01</AnyDate></StartDate><EndDate><AnyDate>2007-01-01</AnyDate></EndDate></PositionHistory><UserArea><employerNameConfidenceRating>75</employerNameConfidenceRating><jobTitleConfidenceRating>0</jobTitleConfidenceRating><startDateConfidenceRating>0</startDateConfidenceRating><endDateConfidenceRating>0</endDateConfidenceRating><datesConfidenceRating>0</datesConfidenceRating><descriptionConfidenceRating>100</descriptionConfidenceRating><positionConfidenceRating>43</positionConfidenceRating></UserArea></EmployerOrg></EmploymentHistory><EducationHistory><SchoolOrInstitution schoolType=\"college\"><School><SchoolName>Des Moines Area Community College Des Moines, IA</SchoolName></School><Degree><DegreeName>AA</DegreeName><DegreeMajor><Name>Art History</Name></DegreeMajor></Degree></SchoolOrInstitution><SchoolOrInstitution schoolType=\"university\"><School><SchoolName>Iowa State University Ames, IA</SchoolName></School><Degree degreeType=\"bachelors\"><DegreeName>BA</DegreeName><DegreeMajor><Name>Art History</Name></DegreeMajor></Degree></SchoolOrInstitution></EducationHistory><Qualifications><Competency name=\"bedding\"><CompetencyId description=\"HireAbility taxonomy\" id=\"9543\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"bedding\" lastUsed=\"2007-01-01\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>BEDDING</OriginalCompetency></Competency><Competency name=\"Customer Service\"><CompetencyId description=\"HireAbility taxonomy\" id=\"91\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Customer Service\" lastUsed=\"2020-01-01\"><NumericValue description=\"Range in years of experience\">7</NumericValue></CompetencyEvidence><OriginalCompetency>CUSTOMER SERVICE</OriginalCompetency></Competency><Competency name=\"Reviews\"><CompetencyId description=\"HireAbility taxonomy\" id=\"8125\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Reviews\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>REVIEWS</OriginalCompetency></Competency><Competency name=\"Sales\"><CompetencyId description=\"HireAbility taxonomy\" id=\"7733\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Sales\" lastUsed=\"2007-01-01\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>SALES</OriginalCompetency></Competency><Competency name=\"Surveys\"><CompetencyId description=\"HireAbility taxonomy\" id=\"17423\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Surveys\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>SURVEYS</OriginalCompetency></Competency><Competency name=\"Triage\"><CompetencyId description=\"HireAbility taxonomy\" id=\"8132\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Triage\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>TRIAGE</OriginalCompetency></Competency><Competency name=\"Troubleshooting\"><CompetencyId description=\"HireAbility taxonomy\" id=\"2283\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Troubleshooting\" lastUsed=\"2020-01-01\"><NumericValue description=\"Range in years of experience\">7</NumericValue></CompetencyEvidence><OriginalCompetency>TROUBLESHOOTING</OriginalCompetency></Competency></Qualifications><PowerZone><SecurityClearance>not specified</SecurityClearance><SecurityPolygraph>not specified</SecurityPolygraph><MilitaryBranch>no</MilitaryBranch><CareerLevel>10+</CareerLevel></PowerZone><Industry>CUSTOMER SERVICE</Industry><JobCategory>CUSTOMER SERVICE</JobCategory><HighestDegree>BACHELOR</HighestDegree><ExperienceSummary><Experience><ExperienceKind>TopSkills</ExperienceKind><Detail>Top 3 skills: TROUBLESHOOTING, BEDDING.</Detail><ExperienceKind>LastSkills</ExperienceKind><Detail>Skills at Current/Last Job: TROUBLESHOOTING.</Detail><ExperienceKind>Summary</ExperienceKind><Years>13</Years><Detail>Total 13 years of experience.</Detail><ExperienceKind>SummaryNamed</ExperienceKind><Years>13</Years><Detail>John has a total of 13 years of experience.</Detail><ExperienceKind>Experience</ExperienceKind><Detail>13 years in customer service, sales</Detail><ExperienceKind>HighestIndustry</ExperienceKind><Years>7</Years><Industry>CUSTOMER SERVICE</Industry><Detail>Highest industry-related experience is 7 years in CUSTOMER SERVICE.</Detail><ExperienceKind>HighestEducation</ExperienceKind><Detail>Received BACHELOR in Art History from Iowa State University Ames, IA</Detail><ExperienceKind>TopLevel</ExperienceKind><Detail>A total of 13 years of work experience. Highest industry-related experience is 7 years in CUSTOMER SERVICE.  Top 3 skills: TROUBLESHOOTING, BEDDING. Skills at Current/Last Job: TROUBLESHOOTING. Received BACHELOR in Art History from Iowa State University Ames, IA </Detail></Experience></ExperienceSummary><Entities><CompanyNames><Company>Bigger Heavy Stuff Inc.</Company><Company>Eddie Bow-wow</Company><Company>Ring-E-Ding Worldwide</Company></CompanyNames><JobTitles><JobTitle>Customer Service Representative</JobTitle></JobTitles><Schools><School>Des Moines Area Community College Des Moines, IA</School><School>Iowa State University Ames, IA</School></Schools><Majors><Major>Art History</Major></Majors></Entities></StructuredXMLResume><Photo mimeType=\"\" dimention=\"\" numberOfPages=\"\"><![CDATA[]]></Photo></Resume><processingErrors><Error id=\"2912536341131\"><ErrorCode></ErrorCode><ErrorMessage></ErrorMessage></Error></processingErrors></HireAbilityXMLResults></Results>

    here is my code that gets this 

    [ValidateAntiForgeryToken]
    [HttpPost]
    public ActionResult Index(int JobID, string FirstName, string MiddleName, string LastName, string Email, HttpPostedFileBase Resume)
    {
    	string product_code = "*****************************";
    	string FileName = Resume.FileName;
    	string encoded = FileName;
    	string UserID = "";
    
    	if(Resume.ContentLength > 0)
    	{
    		string Address = "";
    		string City = "";
    		string State = "";
    		string Zip = "";
    		string AreaCode = "";
    		string LineNumber = "";
    		string Telephone = "";
    		string PhoneType = "";
    
    		string EmployerName = "";
    		string Title = "";
    		string EmployerAddress = "";
    		string EmployerCity = "";
    		string EmployerState = "";
    		string StartDate = "";
    		string EndDate = "";
    		string Duties = "";
    		string FullAddress = "";
    		bool Current = false;
    
    		string ReferenceName = "";
    		string ReferenceAddress = "";
    		string ReferencePhone = "";
    		string ReferenceRelation = "";
    
    		string SchoolName = "";
    		string Degree = "";
    		string Major = "";
    		int Level = 0;
    		int Completed = 0;
    
    		int x = 1;
    
    		string Qualifications = "";
    		string Licenses = "";
    		string Achievements = "";
    
    
    		Applicant applicant = new Applicant();
    
    		//Try to save the data.  If it does not return a userid then the Application for this position has been started or completed.
    		UserID = applicant.StartApplication(FirstName, MiddleName, LastName, JobID, Email, Request.UserHostAddress, Request.UserAgent,"VA");
    
    		if (UserID == "Completed")
    		{
    			ViewBag.Message = "We have a completed application for this position on file.";
    			ViewBag.Completed = true;
    			return View();
    		}
    
    		if (UserID == "XXXXXX")
    		{
    			ViewBag.Message = "We have an incomplete application for this position on file.";
    			ViewBag.Completed = false;
    			return View();
    		}
    
    		//convert resume to base 64 string
    		using (BinaryReader br = new BinaryReader(Resume.InputStream))
    		{
    			int fileSize = Resume.ContentLength;
    			byte[] binaryStream = br.ReadBytes((int)Resume.ContentLength);
    			encoded = Convert.ToBase64String(binaryStream);
    			br.Close();
    		}
    
    		//Instantiate the web service object
    		com.resumeparser.processing.ParsingToolsService hireability = new com.resumeparser.processing.ParsingToolsService();
    		//the first empty element in the next two methods is where we would put our unique identifier.  it is not needed though.
    
    		//Send resume over for parsing and get the results
    		string results = hireability.ParseDocNew(product_code, FileName, encoded, "", "", "", "");
    
    		results = results.Replace("\n", "");
    
    		int startpos = results.IndexOf("<NonXMLResume>");
    		int endpos = results.IndexOf("</NonXMLResume>");
    		int remove = (endpos + 15) - startpos;
    		results = results.Remove(startpos, remove);
    		startpos = results.IndexOf("<!--");
    		endpos = results.IndexOf("<Results>");
    		remove = endpos - startpos;
    		results = results.Remove(startpos, remove);
    
    		var mySerializer = new XmlSerializer(typeof(ResultsHireAbilityXMLResults));
    
    		var reader = new StringReader(results);
    
    		var obj = (ResultsHireAbilityXMLResults)mySerializer.Deserialize(reader);
    	  
    		if(obj.Resume.StructuredXMLResume != null)
    		{
    			var contactMethod = obj.Resume.StructuredXMLResume.ContactInfo.ContactMethod;
    			foreach(var cm in contactMethod)
    			{
    				if(cm.PostalAddress != null)
    				{
    					Address = cm.PostalAddress.DeliveryAddress.AddressLine.ToString();
    					City = cm.PostalAddress.Municipality.ToString();
    					State = cm.PostalAddress.Region.ToString();
    					Zip = cm.PostalAddress.PostalCode.ToString();
    					applicant.AddAddress(UserID, Address.Substring(0, 100), City.Substring(0, 35), State, Zip);
    				}
    				if(cm.Telephone != null)
    				{
    					AreaCode = cm.Telephone.AreaCityCode.ToString();
    					LineNumber = cm.Telephone.SubscriberNumber.ToString();
    					string pType = cm.Location.ToString();
    					switch (pType)
    					{
    						case "home":
    							PhoneType = "Home";
    							break;
    						case "onPerson":
    							PhoneType = "Cell";
    							break;
    						default:
    							PhoneType = "Home";
    							break;
    					}
    					Telephone = AreaCode + "-" + LineNumber;
    					//We have a phone number save it.
    					applicant.AddTelephone(UserID, Telephone, PhoneType);
    				}
    				if(cm.Mobile != null)
    				{
    					AreaCode = cm.Telephone.AreaCityCode.ToString();
    					LineNumber = cm.Telephone.SubscriberNumber.ToString();
    					Telephone = AreaCode + "-" + LineNumber;
    					applicant.AddTelephone(UserID, Telephone, "Cell");
    				}
    			}
    
    			var empHistory = obj.Resume.StructuredXMLResume.EmploymentHistory;
    			foreach(var emp in empHistory)
    			{
    				EmployerName = emp.EmployerOrgName.ToString();
    				EmployerAddress = emp.PositionHistory.OrgInfo.PositionLocation.DeliveryAddress.ToString();
    				EmployerCity = emp.PositionHistory.OrgInfo.PositionLocation.Municipality.ToString();
    				EmployerState = emp.PositionHistory.OrgInfo.PositionLocation.Region.ToString();
    				FullAddress = EmployerAddress + " " + EmployerCity + ", " + EmployerState;
    				if (FullAddress.Length > 50)
    				{
    					FullAddress = EmployerCity + ", " + EmployerState;
    				}
    
    				Title = emp.PositionHistory.Title.ToString();
    
    				Duties = emp.PositionHistory.Description.ToString();
    				StartDate = emp.PositionHistory.StartDate.AnyDate.ToString();
    				EndDate = emp.PositionHistory.EndDate.AnyDate.ToString();
    				if (EndDate == "current")
    				{
    					Current = true;
    				}
    
    				//We have some employer information.  Now save the info to database
    				Employer employer = new Employer();
    				employer.Add(UserID, EmployerName, Title.Substring(0, 50), Duties.Substring(0, 200), FullAddress, StartDate + " - " + EndDate, Current, x);
    				x++;
    			}
    			x = 1;
    
    			var eduHistory = obj.Resume.StructuredXMLResume.EducationHistory;
    			foreach(var edu in eduHistory)
    			{
    				SchoolName = edu.School.SchoolName.ToString();
    				switch (edu.schoolType.ToString())
    				{
    					case "highschool":
    						Level = 1;
    						break;
    					case "university":
    					case "college":
    						Level = 2;
    						break;
    					default:
    						Level = 4;
    						break;
    				}
    				Degree = edu.Degree.DegreeName.ToString();
    				Major = edu.Degree.DegreeMajor.Name.ToString();
    				switch (edu.Degree.degreeType.ToString())
    				{
    					case "bachelors":
    						Level = 2;
    						Completed = 1;
    						break;
    					case "masters":
    					case "postgraduate":
    					case "doctoral":
    						Level = 3;
    						Completed = 1;
    						break;
    					default:
    						Level = 4;
    						break;
    				}
    				//We have education information.  Save the information to database
    				Education school = new Education();
    				school.Add(UserID, SchoolName.Substring(0, 150), Level, Major.Substring(0, 50), Degree.Substring(0, 50), Completed, x);
    				x++;
    			}
    			x = 1;
    
    			var references = obj.Resume.StructuredXMLResume.References;
    			if (references != null)
    			{
    				foreach(var r in references)
    				{
    					ReferenceName = r.Reference.PersonName.FormattedName.ToString();
    					ReferencePhone = r.Reference.ContactMethod.Telephone.AreaCityCode.ToString() + "-" + r.Reference.ContactMethod.Telephone.SubscriberNumber.ToString();
    					ReferenceAddress = r.Reference.ContactMethod.PostalAddress.Municipality.ToString() + "," + r.Reference.ContactMethod.PostalAddress.Region.ToString();
    					ReferenceRelation = r.Reference.PositionTitle.ToString();
    					ProfessionalReferences proRefs = new ProfessionalReferences();
    					proRefs.Add(UserID, ReferenceName, ReferencePhone, ReferenceAddress, ReferenceRelation, x);
    					x++;
    				}
    
    			}
    			var quals = obj.Resume.StructuredXMLResume.Qualifications;
    			foreach (var qual in quals)
    			{
    				Qualifications += qual.name.ToString() + ", ";
    			}
    
    			var licenses = obj.Resume.StructuredXMLResume.LicensesAndCertifications;
    			foreach(var license in licenses)
    			{
    				Licenses += license.LicenseOrCertification.Name.ToString() + " - " + license.LicenseOrCertification.IssuingAuthority.ToString() + "\r\n";
    			}
    
    			var achievements = obj.Resume.StructuredXMLResume.Achievements;
    			foreach(var ach in achievements)
    			{
    				Achievements += ach.Description + ", ";
    			}
    
    			applicant.AddSkills(UserID, Qualifications + Achievements + Licenses);
     
    		}
    		else
    		{
    			string err =  obj.processingErrors.Error.ErrorCode.ToString();
    			 
    			switch (err)
    			{
    				case "8006":
    					ViewBag.Message = "Empty Document.";
    					break;
    				case "8007":
    					ViewBag.Message = "Invalid Document type.";
    					break;
    				case "8009":
    					ViewBag.Message = "Unable to parse a Password Protected document.";
    					break;
    				case "8010":
    					ViewBag.Message = "Document is over the 2MB size limitation.";
    					break;
    				default:
    					ViewBag.Message = obj.processingErrors.Error.ErrorMessage;
    					break;
    			}
    			ViewBag.Completed = false;
    			return View();
    		}
    
    		reader.Close();
    	}
    	else
    	{
    		ViewBag.Message = "No resume was selected to upload.";
    		return View();
    	}
    
    
    	TempData["UserID"] = UserID;
    	return RedirectToAction("AppInfo");
    }

    can someone tell me what I am doing wrong?

    Friday, September 25, 2020 7:30 PM

All replies

  • User475983607 posted

    mj1223

    can someone tell me what I am doing wrong?

    This is a duplicate question.  I illustrated how to deserialize XML using the standard .NET XML libraries in your other thread.  Why are you still writing custom XMl serialization code rather than using built-in tools?

    Secondly, if this is a service call then you should have a stream not a string.  Also the service should provide documentation as to the type to expect with XML Schema.  

    Friday, September 25, 2020 8:02 PM
  • User-2012457684 posted

    mgebhard

    This is a duplicate question.  I illustrated how to deserialize XML using the standard .NET XML libraries in your other thread.  Why are you still writing custom XMl serialization code rather than using built-in tools?

    Secondly, if this is a service call then you should have a stream not a string.  Also the service should provide documentation as to the type to expect with XML Schema.  

    No it is NOT a duplicate question.     It is a follow up to the first one.   

    You give answers that are prefectly fine for someone with your skills but leave the person asking them even more confused than before you replied.   I bow done before your greatness.

    Yes it is coming in from a service.   Before I ever post on here I do a Google search.  When I did so, I found a gazillion answers and most point to it being a string.  So that is what I was using.    When I run the code in debug,  it throws that error.   If I should be using something other than StringReader  Why not point to a good tutorial on what I should do instead of being so condescending.    

    Friday, September 25, 2020 8:16 PM
  • User475983607 posted

    mj1223

    No it is NOT a duplicate question. 

    Yes.  This is a duplicate question.  There were two steps.  Copy the XML and let Visual Studio create the Classes from the XML.  Then simply deserialize the XML.  It's far easier than building your own custom serializer.  Also I suspect the service owners have the XML Schema which you can use.

    The XML in this thread is different than the XML you provided in the other thread.  Which is why you can't use the same class.  Anyway, here's the code to convert the XML string to a stream then into a C# type using the ne XML.

            static string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Results><HireAbilityXMLResults id=\"2912536341131\"  usageLimitType=\"allocation\" usageLimit=\"5003\" currentUsage=\"27\" remainingUsage=\"4976\" accountValidThrough=\"09-15-2021\"><Resume xmlns=\"http://ns.hr-xml.org/2007-04-15\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xml:lang=\"EN\" xsi:schemaLocation=\"https://s3.amazonaws.com/Build_2_5/HR-XML-2_5/SEP/Resume.xsd\"><ResumeId><IdValue/></ResumeId><StructuredXMLResume><ContactInfo><PersonName><FormattedName>John E Doe</FormattedName><GivenName>John</GivenName><MiddleName>E</MiddleName><FamilyName>Doe</FamilyName></PersonName><ContactMethod><PostalAddress><CountryCode>US</CountryCode><PostalCode>1111</PostalCode><Region>IA</Region><Municipality>Sioux City</Municipality><DeliveryAddress><AddressLine>1234 Main St.</AddressLine></DeliveryAddress></PostalAddress></ContactMethod><ContactMethod><Use>personal</Use><Location>home</Location><WhenAvailable>unknown</WhenAvailable><Telephone><FormattedNumber>(712)123-4567</FormattedNumber><InternationalCountryCode>1</InternationalCountryCode><AreaCityCode>712</AreaCityCode><SubscriberNumber>123-4567</SubscriberNumber></Telephone></ContactMethod><ContactMethod><Use>personal</Use><Location>onPerson</Location><WhenAvailable>anytime</WhenAvailable><Mobile><FormattedNumber>(712)555-1234</FormattedNumber><InternationalCountryCode>1</InternationalCountryCode><AreaCityCode>712</AreaCityCode><SubscriberNumber>555-1234</SubscriberNumber></Mobile></ContactMethod><ContactMethod><InternetEmailAddress>John.doe@deermail.com</InternetEmailAddress></ContactMethod></ContactInfo><ExecutiveSummary> * 5+ years of successful customer service experience. * Skilled at communication with internal and external customers as evidence by outstanding satisfaction surveys and performance reviews. * Competent in use of technology to deliver service: automated dialers, sales and service databases, hands-free telephonic devices.</ExecutiveSummary><EmploymentHistory><EmployerOrg><EmployerOrgName>Ring-E-Ding Worldwide</EmployerOrgName><JobType/><PositionHistory><Title>Customer Service Representative</Title><OrgName><OrganizationName/></OrgName><OrgInfo><PositionLocation><CountryCode>US</CountryCode><Region>IA</Region><Municipality>Sioux City</Municipality></PositionLocation></OrgInfo><OrgIndustry primaryIndicator=\"true\"><IndustryDescription>customer service</IndustryDescription></OrgIndustry><Description>Provide world-class customer service support for gamin system users via telephone and live chat formats. * Assist customers with set-up of new devices and troubleshooting of problems. * Utilize diagnostic steps to determine prompt identification of issues and solutions. * Use de-escalation techniques to diffuse customer frustrations. * Offer appropriate services and products to enhance end-user experience. * Document all interactions thoroughly and timely to streamline future interactions between customer and call-center staff.</Description><StartDate><AnyDate>2013-04-01</AnyDate></StartDate><EndDate><AnyDate>current</AnyDate></EndDate></PositionHistory><UserArea><employerNameConfidenceRating>50</employerNameConfidenceRating><jobTitleConfidenceRating>100</jobTitleConfidenceRating><startDateConfidenceRating>100</startDateConfidenceRating><endDateConfidenceRating>100</endDateConfidenceRating><datesConfidenceRating>100</datesConfidenceRating><descriptionConfidenceRating>100</descriptionConfidenceRating><positionConfidenceRating>87</positionConfidenceRating></UserArea></EmployerOrg><EmployerOrg><EmployerOrgName>Eddie Bow-wow</EmployerOrgName><JobType/><PositionHistory><OrgName><OrganizationName/></OrgName><OrgInfo><PositionLocation><CountryCode>US</CountryCode><Region>IA</Region><Municipality>Sioux City</Municipality></PositionLocation></OrgInfo><OrgIndustry primaryIndicator=\"true\"><IndustryDescription>sales</IndustryDescription></OrgIndustry><Description>Assisted dogs and their humans with selection and purchase of quality of life products such as: bedding, feeding, safety, and exercise items. * Maintained a high level of product knowledge in order to suggest alternatives and compare products side-by-side. * Participated in company sales incentive programs and consistently finished in the top 3 Associates district-wide. * Offered appropriate resolutions to customer concerns in order to assure return business. * Recipient of \"Best of Bow-wow\" award for 38 store district.</Description><StartDate><AnyDate>2007-01-01</AnyDate></StartDate><EndDate><AnyDate>2007-01-01</AnyDate></EndDate></PositionHistory><UserArea><employerNameConfidenceRating>50</employerNameConfidenceRating><jobTitleConfidenceRating>0</jobTitleConfidenceRating><startDateConfidenceRating>100</startDateConfidenceRating><endDateConfidenceRating>100</endDateConfidenceRating><datesConfidenceRating>100</datesConfidenceRating><descriptionConfidenceRating>100</descriptionConfidenceRating><positionConfidenceRating>62</positionConfidenceRating></UserArea></EmployerOrg><EmployerOrg><EmployerOrgName>Bigger Heavy Stuff Inc.</EmployerOrgName><JobType/><PositionHistory><OrgName><OrganizationName/></OrgName><OrgInfo><PositionLocation><CountryCode>US</CountryCode><Region>IA</Region><Municipality>Sioux City</Municipality></PositionLocation></OrgInfo><Description>Performed warehouse labor at a Fortune 500 manufacturer of computing devices. * Tagged and labeled containers to identify contents and assure accurate delivery to customer. * Read and interpreted work orders to triage each day's activities * Determined work assignments and equipment needs to maintain efficient use of human and material resources. * Loaded and unloaded materials on semi-trailers using forklifts and pallet jacks.</Description><StartDate><AnyDate>2007-01-01</AnyDate></StartDate><EndDate><AnyDate>2007-01-01</AnyDate></EndDate></PositionHistory><UserArea><employerNameConfidenceRating>75</employerNameConfidenceRating><jobTitleConfidenceRating>0</jobTitleConfidenceRating><startDateConfidenceRating>0</startDateConfidenceRating><endDateConfidenceRating>0</endDateConfidenceRating><datesConfidenceRating>0</datesConfidenceRating><descriptionConfidenceRating>100</descriptionConfidenceRating><positionConfidenceRating>43</positionConfidenceRating></UserArea></EmployerOrg></EmploymentHistory><EducationHistory><SchoolOrInstitution schoolType=\"college\"><School><SchoolName>Des Moines Area Community College Des Moines, IA</SchoolName></School><Degree><DegreeName>AA</DegreeName><DegreeMajor><Name>Art History</Name></DegreeMajor></Degree></SchoolOrInstitution><SchoolOrInstitution schoolType=\"university\"><School><SchoolName>Iowa State University Ames, IA</SchoolName></School><Degree degreeType=\"bachelors\"><DegreeName>BA</DegreeName><DegreeMajor><Name>Art History</Name></DegreeMajor></Degree></SchoolOrInstitution></EducationHistory><Qualifications><Competency name=\"bedding\"><CompetencyId description=\"HireAbility taxonomy\" id=\"9543\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"bedding\" lastUsed=\"2007-01-01\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>BEDDING</OriginalCompetency></Competency><Competency name=\"Customer Service\"><CompetencyId description=\"HireAbility taxonomy\" id=\"91\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Customer Service\" lastUsed=\"2020-01-01\"><NumericValue description=\"Range in years of experience\">7</NumericValue></CompetencyEvidence><OriginalCompetency>CUSTOMER SERVICE</OriginalCompetency></Competency><Competency name=\"Reviews\"><CompetencyId description=\"HireAbility taxonomy\" id=\"8125\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Reviews\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>REVIEWS</OriginalCompetency></Competency><Competency name=\"Sales\"><CompetencyId description=\"HireAbility taxonomy\" id=\"7733\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Sales\" lastUsed=\"2007-01-01\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>SALES</OriginalCompetency></Competency><Competency name=\"Surveys\"><CompetencyId description=\"HireAbility taxonomy\" id=\"17423\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Surveys\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>SURVEYS</OriginalCompetency></Competency><Competency name=\"Triage\"><CompetencyId description=\"HireAbility taxonomy\" id=\"8132\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Triage\"><NumericValue description=\"Range in years of experience\">1</NumericValue></CompetencyEvidence><OriginalCompetency>TRIAGE</OriginalCompetency></Competency><Competency name=\"Troubleshooting\"><CompetencyId description=\"HireAbility taxonomy\" id=\"2283\" idOwner=\"HireAbility\"/><TaxonomyId description=\"HireAbility taxonomy\" idOwner=\"HireAbility\" id=\"\"/><CompetencyEvidence name=\"Troubleshooting\" lastUsed=\"2020-01-01\"><NumericValue description=\"Range in years of experience\">7</NumericValue></CompetencyEvidence><OriginalCompetency>TROUBLESHOOTING</OriginalCompetency></Competency></Qualifications><PowerZone><SecurityClearance>not specified</SecurityClearance><SecurityPolygraph>not specified</SecurityPolygraph><MilitaryBranch>no</MilitaryBranch><CareerLevel>10+</CareerLevel></PowerZone><Industry>CUSTOMER SERVICE</Industry><JobCategory>CUSTOMER SERVICE</JobCategory><HighestDegree>BACHELOR</HighestDegree><ExperienceSummary><Experience><ExperienceKind>TopSkills</ExperienceKind><Detail>Top 3 skills: TROUBLESHOOTING, BEDDING.</Detail><ExperienceKind>LastSkills</ExperienceKind><Detail>Skills at Current/Last Job: TROUBLESHOOTING.</Detail><ExperienceKind>Summary</ExperienceKind><Years>13</Years><Detail>Total 13 years of experience.</Detail><ExperienceKind>SummaryNamed</ExperienceKind><Years>13</Years><Detail>John has a total of 13 years of experience.</Detail><ExperienceKind>Experience</ExperienceKind><Detail>13 years in customer service, sales</Detail><ExperienceKind>HighestIndustry</ExperienceKind><Years>7</Years><Industry>CUSTOMER SERVICE</Industry><Detail>Highest industry-related experience is 7 years in CUSTOMER SERVICE.</Detail><ExperienceKind>HighestEducation</ExperienceKind><Detail>Received BACHELOR in Art History from Iowa State University Ames, IA</Detail><ExperienceKind>TopLevel</ExperienceKind><Detail>A total of 13 years of work experience. Highest industry-related experience is 7 years in CUSTOMER SERVICE.  Top 3 skills: TROUBLESHOOTING, BEDDING. Skills at Current/Last Job: TROUBLESHOOTING. Received BACHELOR in Art History from Iowa State University Ames, IA </Detail></Experience></ExperienceSummary><Entities><CompanyNames><Company>Bigger Heavy Stuff Inc.</Company><Company>Eddie Bow-wow</Company><Company>Ring-E-Ding Worldwide</Company></CompanyNames><JobTitles><JobTitle>Customer Service Representative</JobTitle></JobTitles><Schools><School>Des Moines Area Community College Des Moines, IA</School><School>Iowa State University Ames, IA</School></Schools><Majors><Major>Art History</Major></Majors></Entities></StructuredXMLResume><Photo mimeType=\"\" dimention=\"\" numberOfPages=\"\"><![CDATA[]]></Photo></Resume><processingErrors><Error id=\"2912536341131\"><ErrorCode></ErrorCode><ErrorMessage></ErrorMessage></Error></processingErrors></HireAbilityXMLResults></Results>";
            //static string path = @"C:\Demo\ConsoleApp1\xml\HireAbilityXMLResults.xml";
            static async Task Main (string[] args)
            {
                //Console.WriteLine(xml);
                //return;
                // Construct an instance of the XmlSerializer with the type
                // of object that is being deserialized.
                var mySerializer = new XmlSerializer(typeof(Results));
                // To read the file, create a FileStream.
                //var myFileStream = new FileStream(path, FileMode.Open);
                // Call the Deserialize method and cast to the object type.
                Stream myFileStream = GenerateStreamFromString(xml);
    
                var myObject = (Results)mySerializer.Deserialize(myFileStream);
    
                Console.WriteLine(myObject.HireAbilityXMLResults.id);
                Console.WriteLine(myObject.HireAbilityXMLResults.Resume.StructuredXMLResume.ContactInfo.PersonName.GivenName);
    
            }
    
            public static Stream GenerateStreamFromString(string s)
            {
                var stream = new MemoryStream();
                var writer = new StreamWriter(stream);
                writer.Write(s);
                writer.Flush();
                stream.Position = 0;
                return stream;
            }

    Here's your XML that you can copy and Paste Special -> XML as Classes

    <?xml version="1.0" encoding="UTF-8"?>
    <Results>
      <HireAbilityXMLResults id="2912536341131"  usageLimitType="allocation" usageLimit="5003" currentUsage="27" remainingUsage="4976" accountValidThrough="09-15-2021">
        <Resume xmlns="http://ns.hr-xml.org/2007-04-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="EN" xsi:schemaLocation="https://s3.amazonaws.com/Build_2_5/HR-XML-2_5/SEP/Resume.xsd">
          <ResumeId>
            <IdValue/>
          </ResumeId>
          <StructuredXMLResume>
            <ContactInfo>
              <PersonName>
                <FormattedName>John E Doe</FormattedName>
                <GivenName>John</GivenName>
                <MiddleName>E</MiddleName>
                <FamilyName>Doe</FamilyName>
              </PersonName>
              <ContactMethod>
                <PostalAddress>
                  <CountryCode>US</CountryCode>
                  <PostalCode>1111</PostalCode>
                  <Region>IA</Region>
                  <Municipality>Sioux City</Municipality>
                  <DeliveryAddress>
                    <AddressLine>1234 Main St.</AddressLine>
                  </DeliveryAddress>
                </PostalAddress>
              </ContactMethod>
              <ContactMethod>
                <Use>personal</Use>
                <Location>home</Location>
                <WhenAvailable>unknown</WhenAvailable>
                <Telephone>
                  <FormattedNumber>(712)123-4567</FormattedNumber>
                  <InternationalCountryCode>1</InternationalCountryCode>
                  <AreaCityCode>712</AreaCityCode>
                  <SubscriberNumber>123-4567</SubscriberNumber>
                </Telephone>
              </ContactMethod>
              <ContactMethod>
                <Use>personal</Use>
                <Location>onPerson</Location>
                <WhenAvailable>anytime</WhenAvailable>
                <Mobile>
                  <FormattedNumber>(712)555-1234</FormattedNumber>
                  <InternationalCountryCode>1</InternationalCountryCode>
                  <AreaCityCode>712</AreaCityCode>
                  <SubscriberNumber>555-1234</SubscriberNumber>
                </Mobile>
              </ContactMethod>
              <ContactMethod>
                <InternetEmailAddress>John.doe@deermail.com</InternetEmailAddress>
              </ContactMethod>
            </ContactInfo>
            <ExecutiveSummary> * 5+ years of successful customer service experience. * Skilled at communication with internal and external customers as evidence by outstanding satisfaction surveys and performance reviews. * Competent in use of technology to deliver service: automated dialers, sales and service databases, hands-free telephonic devices.</ExecutiveSummary>
            <EmploymentHistory>
              <EmployerOrg>
                <EmployerOrgName>Ring-E-Ding Worldwide</EmployerOrgName>
                <JobType/>
                <PositionHistory>
                  <Title>Customer Service Representative</Title>
                  <OrgName>
                    <OrganizationName/>
                  </OrgName>
                  <OrgInfo>
                    <PositionLocation>
                      <CountryCode>US</CountryCode>
                      <Region>IA</Region>
                      <Municipality>Sioux City</Municipality>
                    </PositionLocation>
                  </OrgInfo>
                  <OrgIndustry primaryIndicator="true">
                    <IndustryDescription>customer service</IndustryDescription>
                  </OrgIndustry>
                  <Description>Provide world-class customer service support for gamin system users via telephone and live chat formats. * Assist customers with set-up of new devices and troubleshooting of problems. * Utilize diagnostic steps to determine prompt identification of issues and solutions. * Use de-escalation techniques to diffuse customer frustrations. * Offer appropriate services and products to enhance end-user experience. * Document all interactions thoroughly and timely to streamline future interactions between customer and call-center staff.</Description>
                  <StartDate>
                    <AnyDate>2013-04-01</AnyDate>
                  </StartDate>
                  <EndDate>
                    <AnyDate>current</AnyDate>
                  </EndDate>
                </PositionHistory>
                <UserArea>
                  <employerNameConfidenceRating>50</employerNameConfidenceRating>
                  <jobTitleConfidenceRating>100</jobTitleConfidenceRating>
                  <startDateConfidenceRating>100</startDateConfidenceRating>
                  <endDateConfidenceRating>100</endDateConfidenceRating>
                  <datesConfidenceRating>100</datesConfidenceRating>
                  <descriptionConfidenceRating>100</descriptionConfidenceRating>
                  <positionConfidenceRating>87</positionConfidenceRating>
                </UserArea>
              </EmployerOrg>
              <EmployerOrg>
                <EmployerOrgName>Eddie Bow-wow</EmployerOrgName>
                <JobType/>
                <PositionHistory>
                  <OrgName>
                    <OrganizationName/>
                  </OrgName>
                  <OrgInfo>
                    <PositionLocation>
                      <CountryCode>US</CountryCode>
                      <Region>IA</Region>
                      <Municipality>Sioux City</Municipality>
                    </PositionLocation>
                  </OrgInfo>
                  <OrgIndustry primaryIndicator="true">
                    <IndustryDescription>sales</IndustryDescription>
                  </OrgIndustry>
                  <Description>Assisted dogs and their humans with selection and purchase of quality of life products such as: bedding, feeding, safety, and exercise items. * Maintained a high level of product knowledge in order to suggest alternatives and compare products side-by-side. * Participated in company sales incentive programs and consistently finished in the top 3 Associates district-wide. * Offered appropriate resolutions to customer concerns in order to assure return business. * Recipient of "Best of Bow-wow" award for 38 store district.</Description>
                  <StartDate>
                    <AnyDate>2007-01-01</AnyDate>
                  </StartDate>
                  <EndDate>
                    <AnyDate>2007-01-01</AnyDate>
                  </EndDate>
                </PositionHistory>
                <UserArea>
                  <employerNameConfidenceRating>50</employerNameConfidenceRating>
                  <jobTitleConfidenceRating>0</jobTitleConfidenceRating>
                  <startDateConfidenceRating>100</startDateConfidenceRating>
                  <endDateConfidenceRating>100</endDateConfidenceRating>
                  <datesConfidenceRating>100</datesConfidenceRating>
                  <descriptionConfidenceRating>100</descriptionConfidenceRating>
                  <positionConfidenceRating>62</positionConfidenceRating>
                </UserArea>
              </EmployerOrg>
              <EmployerOrg>
                <EmployerOrgName>Bigger Heavy Stuff Inc.</EmployerOrgName>
                <JobType/>
                <PositionHistory>
                  <OrgName>
                    <OrganizationName/>
                  </OrgName>
                  <OrgInfo>
                    <PositionLocation>
                      <CountryCode>US</CountryCode>
                      <Region>IA</Region>
                      <Municipality>Sioux City</Municipality>
                    </PositionLocation>
                  </OrgInfo>
                  <Description>Performed warehouse labor at a Fortune 500 manufacturer of computing devices. * Tagged and labeled containers to identify contents and assure accurate delivery to customer. * Read and interpreted work orders to triage each day's activities * Determined work assignments and equipment needs to maintain efficient use of human and material resources. * Loaded and unloaded materials on semi-trailers using forklifts and pallet jacks.</Description>
                  <StartDate>
                    <AnyDate>2007-01-01</AnyDate>
                  </StartDate>
                  <EndDate>
                    <AnyDate>2007-01-01</AnyDate>
                  </EndDate>
                </PositionHistory>
                <UserArea>
                  <employerNameConfidenceRating>75</employerNameConfidenceRating>
                  <jobTitleConfidenceRating>0</jobTitleConfidenceRating>
                  <startDateConfidenceRating>0</startDateConfidenceRating>
                  <endDateConfidenceRating>0</endDateConfidenceRating>
                  <datesConfidenceRating>0</datesConfidenceRating>
                  <descriptionConfidenceRating>100</descriptionConfidenceRating>
                  <positionConfidenceRating>43</positionConfidenceRating>
                </UserArea>
              </EmployerOrg>
            </EmploymentHistory>
            <EducationHistory>
              <SchoolOrInstitution schoolType="college">
                <School>
                  <SchoolName>Des Moines Area Community College Des Moines, IA</SchoolName>
                </School>
                <Degree>
                  <DegreeName>AA</DegreeName>
                  <DegreeMajor>
                    <Name>Art History</Name>
                  </DegreeMajor>
                </Degree>
              </SchoolOrInstitution>
              <SchoolOrInstitution schoolType="university">
                <School>
                  <SchoolName>Iowa State University Ames, IA</SchoolName>
                </School>
                <Degree degreeType="bachelors">
                  <DegreeName>BA</DegreeName>
                  <DegreeMajor>
                    <Name>Art History</Name>
                  </DegreeMajor>
                </Degree>
              </SchoolOrInstitution>
            </EducationHistory>
            <Qualifications>
              <Competency name="bedding">
                <CompetencyId description="HireAbility taxonomy" id="9543" idOwner="HireAbility"/>
                <TaxonomyId description="HireAbility taxonomy" idOwner="HireAbility" id=""/>
                <CompetencyEvidence name="bedding" lastUsed="2007-01-01">
                  <NumericValue description="Range in years of experience">1</NumericValue>
                </CompetencyEvidence>
                <OriginalCompetency>BEDDING</OriginalCompetency>
              </Competency>
              <Competency name="Customer Service">
                <CompetencyId description="HireAbility taxonomy" id="91" idOwner="HireAbility"/>
                <TaxonomyId description="HireAbility taxonomy" idOwner="HireAbility" id=""/>
                <CompetencyEvidence name="Customer Service" lastUsed="2020-01-01">
                  <NumericValue description="Range in years of experience">7</NumericValue>
                </CompetencyEvidence>
                <OriginalCompetency>CUSTOMER SERVICE</OriginalCompetency>
              </Competency>
              <Competency name="Reviews">
                <CompetencyId description="HireAbility taxonomy" id="8125" idOwner="HireAbility"/>
                <TaxonomyId description="HireAbility taxonomy" idOwner="HireAbility" id=""/>
                <CompetencyEvidence name="Reviews">
                  <NumericValue description="Range in years of experience">1</NumericValue>
                </CompetencyEvidence>
                <OriginalCompetency>REVIEWS</OriginalCompetency>
              </Competency>
              <Competency name="Sales">
                <CompetencyId description="HireAbility taxonomy" id="7733" idOwner="HireAbility"/>
                <TaxonomyId description="HireAbility taxonomy" idOwner="HireAbility" id=""/>
                <CompetencyEvidence name="Sales" lastUsed="2007-01-01">
                  <NumericValue description="Range in years of experience">1</NumericValue>
                </CompetencyEvidence>
                <OriginalCompetency>SALES</OriginalCompetency>
              </Competency>
              <Competency name="Surveys">
                <CompetencyId description="HireAbility taxonomy" id="17423" idOwner="HireAbility"/>
                <TaxonomyId description="HireAbility taxonomy" idOwner="HireAbility" id=""/>
                <CompetencyEvidence name="Surveys">
                  <NumericValue description="Range in years of experience">1</NumericValue>
                </CompetencyEvidence>
                <OriginalCompetency>SURVEYS</OriginalCompetency>
              </Competency>
              <Competency name="Triage">
                <CompetencyId description="HireAbility taxonomy" id="8132" idOwner="HireAbility"/>
                <TaxonomyId description="HireAbility taxonomy" idOwner="HireAbility" id=""/>
                <CompetencyEvidence name="Triage">
                  <NumericValue description="Range in years of experience">1</NumericValue>
                </CompetencyEvidence>
                <OriginalCompetency>TRIAGE</OriginalCompetency>
              </Competency>
              <Competency name="Troubleshooting">
                <CompetencyId description="HireAbility taxonomy" id="2283" idOwner="HireAbility"/>
                <TaxonomyId description="HireAbility taxonomy" idOwner="HireAbility" id=""/>
                <CompetencyEvidence name="Troubleshooting" lastUsed="2020-01-01">
                  <NumericValue description="Range in years of experience">7</NumericValue>
                </CompetencyEvidence>
                <OriginalCompetency>TROUBLESHOOTING</OriginalCompetency>
              </Competency>
            </Qualifications>
            <PowerZone>
              <SecurityClearance>not specified</SecurityClearance>
              <SecurityPolygraph>not specified</SecurityPolygraph>
              <MilitaryBranch>no</MilitaryBranch>
              <CareerLevel>10+</CareerLevel>
            </PowerZone>
            <Industry>CUSTOMER SERVICE</Industry>
            <JobCategory>CUSTOMER SERVICE</JobCategory>
            <HighestDegree>BACHELOR</HighestDegree>
            <ExperienceSummary>
              <Experience>
                <ExperienceKind>TopSkills</ExperienceKind>
                <Detail>Top 3 skills: TROUBLESHOOTING, BEDDING.</Detail>
                <ExperienceKind>LastSkills</ExperienceKind>
                <Detail>Skills at Current/Last Job: TROUBLESHOOTING.</Detail>
                <ExperienceKind>Summary</ExperienceKind>
                <Years>13</Years>
                <Detail>Total 13 years of experience.</Detail>
                <ExperienceKind>SummaryNamed</ExperienceKind>
                <Years>13</Years>
                <Detail>John has a total of 13 years of experience.</Detail>
                <ExperienceKind>Experience</ExperienceKind>
                <Detail>13 years in customer service, sales</Detail>
                <ExperienceKind>HighestIndustry</ExperienceKind>
                <Years>7</Years>
                <Industry>CUSTOMER SERVICE</Industry>
                <Detail>Highest industry-related experience is 7 years in CUSTOMER SERVICE.</Detail>
                <ExperienceKind>HighestEducation</ExperienceKind>
                <Detail>Received BACHELOR in Art History from Iowa State University Ames, IA</Detail>
                <ExperienceKind>TopLevel</ExperienceKind>
                <Detail>A total of 13 years of work experience. Highest industry-related experience is 7 years in CUSTOMER SERVICE.  Top 3 skills: TROUBLESHOOTING, BEDDING. Skills at Current/Last Job: TROUBLESHOOTING. Received BACHELOR in Art History from Iowa State University Ames, IA </Detail>
              </Experience>
            </ExperienceSummary>
            <Entities>
              <CompanyNames>
                <Company>Bigger Heavy Stuff Inc.</Company>
                <Company>Eddie Bow-wow</Company>
                <Company>Ring-E-Ding Worldwide</Company>
              </CompanyNames>
              <JobTitles>
                <JobTitle>Customer Service Representative</JobTitle>
              </JobTitles>
              <Schools>
                <School>Des Moines Area Community College Des Moines, IA</School>
                <School>Iowa State University Ames, IA</School>
              </Schools>
              <Majors>
                <Major>Art History</Major>
              </Majors>
            </Entities>
          </StructuredXMLResume>
          <Photo mimeType="" dimention="" numberOfPages=""><![CDATA[]]></Photo>
        </Resume>
        <processingErrors>
          <Error id="2912536341131">
            <ErrorCode></ErrorCode>
            <ErrorMessage></ErrorMessage>
          </Error>
        </processingErrors>
      </HireAbilityXMLResults>
    </Results>
    

    Friday, September 25, 2020 8:25 PM
  • User-2012457684 posted

    mgebhard

    There were two steps.  Copy the XML and let Visual Studio create the Classes from the XML.  Then simply deserialize the XML.  It's far easier than building your own custom serializer.  Also I suspect the service owners have the XML Schema which you can use.

    The XML in this thread is different than the XML you provided in the other thread.  Which is why you can't use the same class.  Anyway, here's the code to convert the XML string to a stream then into a C# type using the ne XML.

    I did copy some XML and let visual studio create the classes just as you mentioned.  However,  After I found many things wrong, I realized  I could not use what I supplied in the previous example because unbeknownst to me, the vendor had not updated their documentation.  So their example XML was out of date.

    And no I cannot copy and paste the example shown, or the previosu one for that matter because they are both missing things like references, military service, patents, other accomplishments, different languages spoken etc..  However, I found another sample on the vendors website and used the schema to build out examples of multiple schools and multiple jobs and multiple pretty much everything then used that to let Visual Studio create the classes as you suggested in the first response.    This way when it came to Employers and the other items I could use a foreach to get each one.   Otherwise as I posted yesterday  Visual Studio was creating the properties as string  and not string[] 

    So I have that part correct.  I am NOT using the class created from the original example but a new and updated one.  One that covers every imaginable C.V. that someone will upload and that I need to get the values from.   

    Now  since this is a service that will be replying with results I found I could not use your FileStream method because there is no path as it is NEVER going to be coming from a path on the server.    So I did what I always do and went to Google for answers and found one on stack overflow, and that was what I used in my original post in this thread.   

    I saved the information to a string so that I could remove a lot of crap that they sent back that was causing errors.  (there is a node called NonXMLResume that has information in there that is NOT contained in a CDATA tag and was blowing up in visual studio with invalid character errors)

    here is another question you will see as simple but, I am trying to learn this stuff, so how do I use your GenerateStreamfromString method?   once it has been added?

    Friday, September 25, 2020 9:15 PM
  • User475983607 posted

    Now  since this is a service that will be replying with results I found I could not use your FileStream method because there is no path as it is NEVER going to be coming from a path on the server.    So I did what I always do and went to Google for answers and found one on stack overflow, and that was what I used in my original post in this thread.   

    A stream is a steam regardless of the source; HDD or network IO.  

    I saved the information to a string so that I could remove a lot of crap that they sent back that was causing errors.  (there is a node called NonXMLResume that has information in there that is NOT contained in a CDATA tag and was blowing up in visual studio with invalid character errors)

    I took the time to write two working examples from the XML that you provided.  There is not much I can do if you are removing XML nodes.  I can only see the information you share on the forum. 

    Typically, XML services provide XML Schemas which define the input and output objects.  This allow any platform to serialize/deserialize the XML steam using standard development tooling. 

    I recommend reading the service documentation and/or reaching out to the service owners for assistance.  

    Friday, September 25, 2020 10:34 PM
  • User-2012457684 posted

    OK  getting soo close

    When Visual Studio created the classes it created DateTime datatype for dates.  However this uses string datatypes in the schema and so it threw errors on nodes that it thought were supposed to be dates but had text in them.

    So I went through the classes visual studio created and comment out each place it had this 

    [System.Xml.Serialization.XmlAttributeAttribute(DataType = "date")]

    and changed every thing to be string.

    So now it does not throw errors on loading it. 

    And in fact it makes it into my code where i am reading values.  I set some breakpoints  on these  

    string name = obj.HireAbilityXMLResults.Resume.StructuredXMLResume.ContactInfo.PersonName.GivenName.ToString();
    
    var contactMethod = obj.HireAbilityXMLResults.Resume.StructuredXMLResume.ContactInfo.ContactMethod;
    foreach(var cm in contactMethod)
    {
        if(cm.PostalAddress != null)
        {
            Address = cm.PostalAddress.DeliveryAddress.AddressLine.ToString();
            City = cm.PostalAddress.Municipality.ToString();
            State = cm.PostalAddress.Region.ToString();
            Zip = cm.PostalAddress.PostalCode.ToString();
            applicant.AddAddress(UserID, Address.Substring(0, 100), City.Substring(0, 35), State, Zip);
        }

    However when I try to read the value for it and every other field in Autos what I see instead is "System.Xml.XmlNode[]" for the values.   

    Information in Autos

    		Address	"System.Xml.XmlNode[]"	string
    		City	"System.Xml.XmlNode[]"	string
    		State	"System.Xml.XmlNode[]"	string
    		UserID	"VA8255163"	string
    		Zip	"System.Xml.XmlNode[]"	string
    +		applicant	{ResumeParser.Models.Applicant}	ResumeParser.Models.Applicant
    -		cm.PostalAddress.PostalCode	{System.Xml.XmlNode[1]}	object {System.Xml.XmlNode[]}
    -		[0]	{Text, Value="1111"}	System.Xml.XmlNode {System.Xml.XmlText}
    		Attributes	null	System.Xml.XmlAttributeCollection
    		BaseURI	""	string
    +		ChildNodes	{System.Xml.XmlChildNodes}	System.Xml.XmlNodeList {System.Xml.XmlChildNodes}
    		Data	"1111"	string
    		FirstChild	null	System.Xml.XmlNode
    		HasChildNodes	false	bool
    		InnerText	"1111"	string
    		InnerXml	""	string
    		IsReadOnly	false	bool
    		LastChild	null	System.Xml.XmlNode
    		Length	4	int
    		LocalName	"#text"	string
    		Name	"#text"	string
    		NamespaceURI	""	string
    		NextSibling	null	System.Xml.XmlNode
    		NodeType	Text	System.Xml.XmlNodeType
    		OuterXml	"1111"	string
    +		OwnerDocument	{Document}	System.Xml.XmlDocument
    +		ParentNode	{Element, Name="PostalCode"}	System.Xml.XmlNode {System.Xml.XmlElement}
    		Prefix	""	string
    		PreviousSibling	null	System.Xml.XmlNode
    		PreviousText	null	System.Xml.XmlNode
    +		SchemaInfo	{System.Xml.Schema.XmlSchemaInfo}	System.Xml.Schema.IXmlSchemaInfo {System.Xml.Schema.XmlSchemaInfo}
    		Value	"1111"	string
    +		Non-Public members		
    +		Results View	Expanding the Results View will enumerate the IEnumerable	
    +		this	{ResumeParser.Controllers.HomeController}	ResumeParser.Controllers.HomeController
    

    Friday, September 25, 2020 11:16 PM
  • User-2012457684 posted

    I am getting really close to having this working properly.  The issue I had was while the vendor supplied a couple different examples of the XML to use, they both had issues.    on the first example I had tried to clean up the xml before posting it so that you did not see bad xml, the example they have int eh documentation is not valid and if copied and pasted into a document or visual studio you would have seen the nodes closed out of place.   

    1. Hoever, i did not know that In the documentation the xml provided was out of date.  It uses HR-XML which is updated from time to time and this example was before the previous update.  so when I used that example to build the classes of course it did not work when newer xml was sent in as the string.  
    2. The second example did not have more than 1 of the possible enumerable nodes,  This is results coming back from a resume parsing web service.  Since different people can have different experiences, and I am using this to prefill parts of an employment application for them(because people are LAZY and don't want to fill it out theirself), I needed to create a fictitious resume with different experinces and could then use that to create the classes in Visual Studio.
    3. Visual Studio wanted to create DateTime data type when it saw dates in some of the fields.  However, the value that was being input was string not datetime even though in the sample they input dates.  But it could be just the year,  or month and year, or even the word current.  So I needed to then edit the classes Visual Studio created to change ALL of the DateTime data types to be string.   

    Now that the created classes are correct it is displaying the values to me.   Well almost all of it.   While going through the ContactMethod with my foreach loop I ran into an instance when it told me the

    'object reference was not set to an instance of an object'   

    except I could see the object in the xml and in the autos window while i was in the line above the one it threw the error on.

    here is the part of the xml string that has the data ( I formatted that part so it is easier to read)

    <ContactMethod>
        <PostalAddress>
            <CountryCode>US</CountryCode><PostalCode>1111</PostalCode><Region>IA</Region><Municipality>Sioux City</Municipality><DeliveryAddress><AddressLine>1234 Main St.</AddressLine></DeliveryAddress>
        </PostalAddress>
    </ContactMethod>
    <ContactMethod>
        <Use>personal</Use>
        <Location>home</Location>
        <WhenAvailable>unknown</WhenAvailable>
        <Telephone>
            <FormattedNumber>(712)123-4567</FormattedNumber><InternationalCountryCode>1</InternationalCountryCode><AreaCityCode>712</AreaCityCode><SubscriberNumber>123-4567</SubscriberNumber>
        </Telephone>
    </ContactMethod>
    <ContactMethod>
        <Use>personal</Use>
        <Location>onPerson</Location>
        <WhenAvailable>anytime</WhenAvailable>
    <!--This is the area where it threw an error -->
        <Mobile>
            <FormattedNumber>(712)555-1234</FormattedNumber>
            <InternationalCountryCode>1</InternationalCountryCode>
            <AreaCityCode>712</AreaCityCode>
            <SubscriberNumber>555-1234</SubscriberNumber>
        </Mobile>
    </ContactMethod>
    <ContactMethod>
        <InternetEmailAddress>John.doe@deermail.com</InternetEmailAddress>
    </ContactMethod>

    here is the part of the code that has the foreach loop for ContactMethod.  It threw the error on the 3rd iteration through where it was reading the AreaCityCode for the Mobile number

    foreach(var cm in contactMethod)
    {
        if(cm.PostalAddress != null)
        {
            Address = cm.PostalAddress.DeliveryAddress.AddressLine.ToString();
            City = cm.PostalAddress.Municipality.ToString();
            State = cm.PostalAddress.Region.ToString();
            Zip = cm.PostalAddress.PostalCode.ToString();
            //applicant.AddAddress(UserID, Address.Substring(0, 100), City.Substring(0, 35), State, Zip);
        }
        if(cm.Telephone != null)
        {
            AreaCode = cm.Telephone.AreaCityCode.ToString();
            LineNumber = cm.Telephone.SubscriberNumber.ToString();
            string pType = cm.Location.ToString();
            switch (pType)
            {
                case "home":
                    PhoneType = "Home";
                    break;
                case "onPerson":
                    PhoneType = "Cell";
                    break;
                default:
                    PhoneType = "Home";
                    break;
            }
            Telephone = AreaCode + "-" + LineNumber;
            //We have a phone number save it.
            // applicant.AddTelephone(UserID, Telephone, PhoneType);
        }
        if(cm.Mobile != null)
        {
            // This next line is the one it threw the eror on    
    AreaCode = cm.Telephone.AreaCityCode.ToString(); LineNumber = cm.Telephone.SubscriberNumber.ToString(); Telephone = AreaCode + "-" + LineNumber; //applicant.AddTelephone(UserID, Telephone, "Cell"); } }

    Any idea why it does not see the info ?

     

    Monday, September 28, 2020 9:27 PM
  • User475983607 posted

    Any idea why it does not see the info ?

    For the fourth time.  The service owners are responsible for providing accurate documentation and the XML schema.   Forwarding XML that you modified does not help the ASP.NET forums community help you. It just makes us wonder why...

    Tuesday, September 29, 2020 12:23 AM