I have an XML that i am trying to serialize to a class but i am unable to fathom why the object is null.
null object
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns0:vendResponse xmlns:ns0="http://mynamespace.co/ns0">
<ns0:sequence>234532532221</ns0:sequence>
<ns0:CId>0</ns0:CId>
<ns0:RefId>202675454545453434343</ns0:RefId>
<ns0:origAcct>20.00</ns0:origAcct>
<ns0:destAcct>00087646564</ns0:destAcct>
<ns0:responseCode>0</ns0:responseCode>
<ns0:responseMessage>Successful</ns0:responseMessage>
</ns0:vendResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
var contentStream = File.ReadAllText("response.xml");
Envelope resultEnvelope = new Envelope();
using (var stringReader = new StringReader(contentStream))
{
using (XmlReader reader = new XmlTextReader(stringReader))
{
var serializer1 = new XmlSerializer(typeof(Envelope));
resultEnvelope = serializer1.Deserialize(reader) as Envelope;
}
}
the soap Envelope class generated in VS using paste XML as classes:
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
using System.Data;
namespace ConsoleApplication23
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XmlReader reader = XmlReader.Create(FILENAME);
XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
Envelope envelope = (Envelope)serializer.Deserialize(reader);
}
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement("Body")]
public Body body { get; set; }
}
public class Body
{
[XmlElement(ElementName = "vendResponse", Namespace = "http://mynamespace.co/ns0")]
public VendResponse vendResponse { get; set; }
}
public class VendResponse
{
public string sequence { get; set; }
public string CId { get; set; }
public string RefId { get; set; }
public string origAcct { get; set; }
public string destAcct { get; set; }
public int responseCode { get; set; }
public string responseMessage { get; set; }
}
}
Related
So im struggling to change the namespace for specific nodes in an XML.
This is what i want to achieve:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.justapage.com/webservices/">
<SOAP-ENV:Body>
<ns1:products_Update>
<ns1:login>
...
</ns1:login>
<ns1:products>
<ns1:product>
...
</ns1:product>
</ns1:products>
</ns1:products_Update>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But the results always turns out like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.justapage.com/webservices/">
<SOAP-ENV:Body>
<SOAP-ENV:products_Update>
<SOAP-ENV:login>
...
</SOAP-ENV:login>
<SOAP-ENV:products>
<SOAP-ENV:product>
...
</SOAP-ENV:product>
</SOAP-ENV:products>
</SOAP-ENV:products_Update>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And this is how i serialize it:
public static async Task<string> SerializeSendMessage<T>(this T toSerialize)
{
string returnString;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
XmlSerializer xsSubmit = new XmlSerializer(typeof(T));
using (StringWriter sw = new StringWriter())
using (XmlWriter writer = XmlWriter.Create(sw))
{
var xmlns = new XmlSerializerNamespaces();
xmlns.Add("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
xmlns.Add("ns1", "http://www.justapage.com/webservices/");
xsSubmit.Serialize(writer, toSerialize,xmlns);
returnString = sw.ToString(); // Your XML
}
return returnString;
}
The class:
[XmlRoot(ElementName="Envelope",IsNullable = false)]
public class ArticleEnvelope
{
[XmlElement(ElementName = "Body",Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "SOAP-ENV")]
public string SOAPENV { get; set; }
[XmlAttribute(AttributeName = "ns1")]
public string Ns1 { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Body")]
public class Body
{
[XmlElement(ElementName = "products_Update")]
public ProductsUpdate ProductsUpdate { get; set; }
}
[XmlRoot(ElementName = "products_Update")]
public class ProductsUpdate
{
[XmlElement(ElementName = "login")]
public Login Login { get; set; }
[XmlElement(ElementName = "products")]
public Products Products { get; set; }
}
[XmlRoot(ElementName = "products")]
public class Products
{
[XmlElement(ElementName = "product")]
public List<Product> Product { get; set; }
}
}
I have tried to find some information about this but with no success and I now hope that someone here can point me into the right direction on how to acheive this.
Try following :
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace ConsoleApp2
{
class Program
{
static ArticleEnvelope envelope { get; set; }
static void Main(string[] args)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
XmlSerializer xsSubmit = new XmlSerializer(typeof(ArticleEnvelope));
using (StringWriter sw = new StringWriter())
using (XmlWriter writer = XmlWriter.Create(sw))
{
var xmlns = new XmlSerializerNamespaces();
xmlns.Add("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
xmlns.Add("ns1", "http://www.justapage.com/webservices/");
xsSubmit.Serialize(writer, envelope, xmlns);
}
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/", IsNullable = false)]
public class ArticleEnvelope
{
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlText]
public string Text { get; set; }
}
public class Body
{
[XmlElement(ElementName = "products_Update", Namespace = "http://www.justapage.com/webservices/")]
public ProductsUpdate ProductsUpdate { get; set; }
}
public class ProductsUpdate
{
[XmlElement(ElementName = "login", Namespace = "http://www.justapage.com/webservices/")]
public Login Login { get; set; }
[XmlArray(ElementName = "products", Namespace = "http://www.justapage.com/webservices/")]
[XmlArrayItem(ElementName = "product", Namespace = "http://www.justapage.com/webservices/")]
public List<Product> Products { get; set; }
}
public class Login
{
}
public class Product
{
}
}
This is an XML example I want to deserialize and use in a Desktop App, where the user could insert an XML like this one:
<Settings>
<FileName>C:\Users\myniceuser\Desktop\hello.xmldoc</FileName>
<Zones>
<Row1>
<Address>2</Address>strong text
<Zone>2</Zone>
<Installed>True</Installed>
</Row1>
<Row2>
<Address>3</Address>
<Zone>2</Zone>
<Installed>True</Installed>
</Row2>
<Row3>
<Address>4</Address>
<Zone>2</Zone>
<Installed>True</Installed>
</Row3>
<Row4>
<Address>5</Address>
<Zone>2</Zone>
<Installed>True</Installed>
</Row4>
</Zones>
<Network_IP>010.000.008.072</Network_IP>
<Ethernet_Enable>true</Ethernet_Enable>
<Language>1</Language>
</Settings>
The class I implemented is this one:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace MyApp.Models
{
[XmlRoot(ElementName = "Settings")]
public class XML_Settings
{
[XmlElement(ElementName = "FileName")]
public string FileName { get; set; }
//[XmlElement(ElementName = "Zones")]
[XmlElement(ElementName ="Zones")]
public Zones_Points[] Zones_Points { get; set; }
[XmlElement(ElementName = "Network_IP")]
public string NetworkIP { get; set; }
[XmlElement(ElementName = "Ethernet_Enable")]
public bool EthernetEnable { get; set; }
[XmlElement(ElementName = "Language")]
public int Language { get; set; }
}
[XmlRoot(ElementName = "")]
public partial class Zones_Points
{
[XmlElement(ElementName ="Address")]
public int Address { get; set; }
[XmlElement(ElementName ="Zone")]
public int PointZone { get; set; }
[XmlElement(ElementName ="Installed")]
public bool Installed { get; set; }
}
}
I deserialize like this:
Models.XML_Settings inputted_xml = new();
using StreamReader stream_xml = new StreamReader(xmlfile_path, CodePagesEncodingProvider.Instance.GetEncoding(1253));
XmlSerializer serializer = new XmlSerializer(typeof(Models.XML_Settings));
try
{
Models.XML_Settings input = (Models.XML_GR6500)serializer.Deserialize(stream_xml);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
I want my app to input files in XML like this one, and convert their data to a class that i can use.
The object "input" created by the Deserialization got every data correct, except the Zones, those that in XML have the "Row" tags. Those "rows" could every time be more or less that 4.
What can I do to have the items with the row tags deserialized and inputted into a Zones_Points list or array?
Use IXmlSerializable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Xml.Linq;
namespace ConsoleApplication2
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XmlReader reader = XmlReader.Create(FILENAME);
XmlSerializer serializer = new XmlSerializer(typeof(XML_Settings));
XML_Settings settings = (XML_Settings)serializer.Deserialize(reader);
}
}
[XmlRoot("Settings")]
public class XML_Settings
{
[XmlElement(ElementName = "FileName")]
public string FileName { get; set; }
[XmlElement(ElementName = "Zones")]
public Zones_Points Zones_Point { get; set; }
[XmlElement(ElementName = "Network_IP")]
public string NetworkIP { get; set; }
[XmlElement(ElementName = "Ethernet_Enable")]
public bool EthernetEnable { get; set; }
[XmlElement(ElementName = "Language")]
public int Language { get; set; }
}
public partial class Zones_Points : IXmlSerializable
{
// Xml Serialization Infrastructure
[XmlElement(ElementName = "Zones")]
public List<Zones_Point> Points { get; set; }
public void WriteXml(XmlWriter writer)
{
}
public void ReadXml(XmlReader reader)
{
XElement zones = (XElement)XElement.ReadFrom(reader);
Points = new List<Zones_Point>();
foreach (XElement row in zones.Elements())
{
Zones_Point Point = new Zones_Point();
Points.Add(Point);
Point.Address = (int)row.Element("Address");
Point.PointZone = (int)row.Element("Zone");
Point.Installed = (Boolean)row.Element("Installed");
}
}
public XmlSchema GetSchema()
{
return (null);
}
}
public partial class Zones_Point
{
[XmlElement(ElementName = "Address")]
public int Address { get; set; }
[XmlElement(ElementName = "Zone")]
public int PointZone { get; set; }
[XmlElement(ElementName = "Installed")]
public bool Installed { get; set; }
}
}
I have a xml files in following format:
<?xml version=""1.0"" encoding=""UTF-8""?>
<Options>
<Header>
<H1>A</H1>
<H2>B</H2>
<H3>C</H3>
</Header>
<Include>
<Option A1="something" A2="something">SomeValue</Option>
<Option A1="something" A2="something">SomeOtherValue</Option>
</Include>
</Options>
I managed to use a serializer to de-serialize headers, but run into trouble with options. Specifically I have the following C# objects:
[XmlRoot(ElementName="Option")]
public class Option {
[XmlAttribute(AttributeName="A1")]
public string A1 { get; set; }
[XmlAttribute(AttributeName="A2")]
public string A2 { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName="Include")]
public class OptionList {
[XmlArrayItem("Option")]
public List<Option> Options { get; set; }
}
And I use this serializer to do conversion:
public IReadOnlyList<Option> ParseInclude(string xmlDocument)
{
using (var reader = new XmlTextReader(new StringReader(xmlDocument)))
{
var serializer = new XmlSerializer(typeof(OptionList));
reader.ReadToFollowing("Include");
var collection = (OptionList) serializer.Deserialize(reader);
return collection .Options ;
}
}
But I cannot get it work - I am constantly getting NullReferenceException at the return statement because Options is null. Any ideas?
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
string xmlDocument = File.ReadAllText(FILENAME);
using (XmlReader reader = XmlReader.Create(new StringReader(xmlDocument)))
{
XmlSerializer serializer = new XmlSerializer(typeof(Option));
Option collection = (Option)serializer.Deserialize(reader);
}
}
}
[XmlRoot(ElementName = "Options")]
public class Option
{
public Header Header { get; set; }
[XmlArray("Include")]
[XmlArrayItem("Option")]
public List<OptionList> Options { get; set; }
}
public class Header
{
public string H1 { get; set; }
public string H2 { get; set; }
public string H3 { get; set; }
}
public class OptionList
{
[XmlAttribute(AttributeName = "A1")]
public string A1 { get; set; }
[XmlAttribute(AttributeName = "A2")]
public string A2 { get; set; }
[XmlText]
public string Text { get; set; }
}
}
This is my XML:
<?xml version="1.0" encoding="utf-8"?>
<Fruit>
<Fruit_group name='Tropical'>
<fruit_types name ='Tropical Used'>
<fruit>bananas</fruit>
<fruit>mangoes</fruit>
</fruit_types>
</Fruit_group>
<Fruit_group name='Citrus'>
<fruit_types name ='Citruses Used'>
<fruit>orange</fruit>
<fruit>lime</fruit>
<fruit>grapefruit</fruit>
<excluded_fruits>
<fruit>mandarin</fruit>
</excluded_fruits>
</fruit_types>
</Fruit_group>
</Fruit>
And this is a sample of my XML text..
Is there a way to deserialize it and keep the name of the elements too..
I mean I would like to have like:
Tropical -> Tropical Used -> fruit -> bananas, mangoes
Citrus->Citruses Used ->
fruit = orange, lime, grapefruit
excluded = mandarin....
Something like this...
Could someone help me to understand how does this work?
You can use XML to c# website to create a class according to XML.
In this case, I've got this example
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace Xml2CSharp
{
[XmlRoot(ElementName="fruit_types")]
public class Fruit_types {
[XmlElement(ElementName="fruit")]
public List<string> Fruit { get; set; }
[XmlAttribute(AttributeName="name")]
public string Name { get; set; }
[XmlElement(ElementName="excluded_fruits")]
public Excluded_fruits Excluded_fruits { get; set; }
}
[XmlRoot(ElementName="Fruit_group")]
public class Fruit_group {
[XmlElement(ElementName="fruit_types")]
public Fruit_types Fruit_types { get; set; }
[XmlAttribute(AttributeName="name")]
public string Name { get; set; }
}
[XmlRoot(ElementName="excluded_fruits")]
public class Excluded_fruits {
[XmlElement(ElementName="fruit")]
public string Fruit { get; set; }
}
[XmlRoot(ElementName="Fruit")]
public class Fruit {
[XmlElement(ElementName="Fruit_group")]
public List<Fruit_group> Fruit_group { get; set; }
}
}
Also, You could read this article about XML deserialization.
I suggest using xmltocsharp to convert the XML to Model and do required alterations. For example change the string to List<string> under Excluded_fruits
[XmlRoot(ElementName = "fruit_types")]
public class Fruit_types
{
[XmlElement(ElementName = "fruit")]
public List<string> Fruit { get; set; }
[XmlAttribute(AttributeName = "name")]
public string Name { get; set; }
[XmlElement(ElementName = "excluded_fruits")]
public Excluded_fruits Excluded_fruits { get; set; }
}
[XmlRoot(ElementName = "Fruit_group")]
public class Fruit_group
{
[XmlElement(ElementName = "fruit_types")]
public Fruit_types Fruit_types { get; set; }
[XmlAttribute(AttributeName = "name")]
public string Name { get; set; }
}
[XmlRoot(ElementName = "excluded_fruits")]
public class Excluded_fruits
{
[XmlElement(ElementName = "fruit")]
public List<string> Fruit { get; set; }
}
[XmlRoot(ElementName = "Fruit")]
public class Fruit
{
[XmlElement(ElementName = "Fruit_group")]
public List<Fruit_group> Fruit_group { get; set; }
}
Once the model is ready, you can use XmlSerializer to Deserialize the xml file
using (StreamReader r = new StreamReader(xmlfilepath))
{
string xmlString = r.ReadToEnd();
XmlSerializer ser = new XmlSerializer(typeof(Fruit));
using (TextReader reader = new StringReader(xmlString))
{
var fruits = (Fruit)ser.Deserialize(reader);
foreach(var fruitgroup in fruits.Fruit_group)
{
Console.Write($"{fruitgroup.Name} -> ");
Console.Write($"{fruitgroup.Fruit_types.Name} -> ");
Console.Write($"fruit = {string.Join(",", fruitgroup.Fruit_types.Fruit.ToArray())}; ");
if (fruitgroup.Fruit_types.Excluded_fruits?.Fruit?.Count() > 0)
Console.Write($"excluded = {string.Join(",", fruitgroup.Fruit_types.Excluded_fruits.Fruit.ToArray())}{Environment.NewLine}");
else
Console.WriteLine();
}
}
}
I like getting flatter results doing a custom parsing using xml linq :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
List<Fruit_Group> groups = doc.Descendants("Fruit_group").Select(x => new Fruit_Group()
{
groupName = (string)x.Attribute("name"),
typeName = (string)x.Element("fruit_types").Attribute("name"),
fruits = x.Elements("fruit_types").Elements("fruit").Select(y => (string)y).ToArray(),
excluded = x.Descendants("excluded_fruits").Elements("fruit").Select(y => (string)y).ToArray()
}).ToList();
}
}
public class Fruit_Group
{
public string groupName { get; set;}
public string typeName { get; set; }
public string[] fruits { get; set; }
public string[] excluded { get; set; }
}
}
I am trying to extract the data contained the
in the a SOAP Response XML that I have that contains multiple and variable namespaces in an SSIS Script component using C#.
My XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns3:getCacheEntryResponse xmlns:ns3="http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef/IndividualCommercialService" xmlns:ns2="http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef" xmlns:ns4="http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef/IndividualCommercialDecision" xmlns:ns5="http://vedaadvantage.com/dp3/service/fault" xmlns:ns6="http://com/vedaadvantage/dp3/businessDecisionResultOverride" xmlns:ns7="http://com.vedaadvantage/dp3/connectors" xmlns:ns8="http://com.vedaadvantage/dp3/connectors/vedaxml/vedascore" xmlns:ns9="http://com.vedaadvantage/dp3/connectors/vedaxml/individualalerts">
<ns3:CacheEntry>
<cacheEntryData><Response xmlns="http://com.vedaadvantage/dp3/connectors/vedaxml/vedascore" xmlns:b="http://com.vedaadvantage/dp3/connectors"><enquiryReport><primaryMatch><bureauReference>805917662</bureauReference><individual><individualName><familyName>MOHAMMADINEJAD</familyName><firstGivenName>ALI</firstGivenName><createDate>2014-07-15</createDate></individualName><gender>male</gender><dateOfBirth>1982-01-06</dateOfBirth><driversLicenceNumber><countryCodes>AU</countryCodes><value/></driversLicenceNumber><b:address><b:unitNumber/><b:streetNumber>43</b:streetNumber><b:property>43</b:property><b:streetName>KING EDWARD</b:streetName><b:streetType>AVE</b:streetType><b:suburb>ALBION</b:suburb><b:city/><b:state>VIC</b:state><b:postcode>3020</b:postcode><b:countryCode>AU</b:countryCode><b:addressType>residentialCurrent</b:addressType><b:createDate>2015-09-04</b:createDate></b:address></individual><individualConsumerCreditFile><creditEnquiry><accountType><accountType>UA</accountType><value>Utilities</value></accountType><role><consumerRoleTypeCodesResponse>principal</consumerRoleTypeCodesResponse></role><enquiryAmount><currencyCodeType/><value>0</value></enquiryAmount><coBorrower/><creditEnquirer>AGL ENGY SALES & MKTG LTD</creditEnquirer><clientReference/><consumerCreditEnquiryTypeResponse>creditApplication</consumerCreditEnquiryTypeResponse><enquiryDate>2015-09-04</enquiryDate></creditEnquiry><creditEnquiry><accountType><accountType>TC</accountType><value>Telecommunication Service</value></accountType><role><consumerRoleTypeCodesResponse>principal</consumerRoleTypeCodesResponse></role><enquiryAmount><currencyCodeType/><value>0</value></enquiryAmount><coBorrower/><creditEnquirer>VODAFONE DECISION POINT</creditEnquirer><clientReference>1-DCQJWZG</clientReference><consumerCreditEnquiryTypeResponse>creditApplication</consumerCreditEnquiryTypeResponse><enquiryDate>2014-07-15</enquiryDate></creditEnquiry></individualConsumerCreditFile><individualCommercialCreditFile><creditEnquiry><accountType><commercialAccountTypeCodesResponse>CR</commercialAccountTypeCodesResponse><value>Commercial Rental</value></accountType><enquiryAmount><currencyCodeType/><value>25000</value></enquiryAmount><role><commercialRoleTypeCodesResponse>principal</commercialRoleTypeCodesResponse></role><coBorrower/><creditEnquirer>GOGETTA EQUIPMENT FUNDING</creditEnquirer><clientReference/><commercialCreditEnquiryTypeResponse>creditEnquiry</commercialCreditEnquiryTypeResponse><enquiryDate>2016-04-04</enquiryDate></creditEnquiry></individualCommercialCreditFile><matchType>strong</matchType></primaryMatch><summaryData><summary><name>enquiry-amount</name><summaryType>amount</summaryType><currencyCode>AUD</currencyCode><value>25000</value></summary><summary><name>age-of-file</name><summaryType>months</summaryType><currencyCode/><value>20</value></summary><summary><name>age-of-subject</name><summaryType>years</summaryType><currencyCode/><value>34</value></summary><summary><name>time-at-address</name><summaryType>months</summaryType><currencyCode/><value>7</value></summary><summary><name>time-at-employer</name><summaryType>months</summaryType><currencyCode/><value/></summary><summary><name>defaults</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>total-value-of-outstanding-defaults</name><summaryType>amount</summaryType><currencyCode>AUD</currencyCode><value>0</value></summary><summary><name>defaults-paid</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>defaults-12</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>defaults-12-paid</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>defaults-12-unpaid</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>defaults-24-paid</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>defaults-24-unpaid</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>defaults-36-paid</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>defaults-36-unpaid</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>time-since-last-default</name><summaryType>months</summaryType><currencyCode/><value/></summary><summary><name>total-credit-enquiries</name><summaryType>count</summaryType><currencyCode/><value>3</value></summary><summary><name>credit-enquiries-1</name><summaryType>count</summaryType><currencyCode/><value>1</value></summary><summary><name>credit-enquiries-3</name><summaryType>count</summaryType><currencyCode/><value>1</value></summary><summary><name>credit-enquiries-6</name><summaryType>count</summaryType><currencyCode/><value>1</value></summary><summary><name>credit-enquiries-12</name><summaryType>count</summaryType><currencyCode/><value>2</value></summary><summary><name>credit-enquiries-60</name><summaryType>count</summaryType><currencyCode/><value>3</value></summary><summary><name>time-since-last-enquiry</name><summaryType>months</summaryType><currencyCode/><value>7</value></summary><summary><name>telco-and-utility-defaults</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>telco-and-utility-defaults-12</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>telco-and-utility-enquiries</name><summaryType>count</summaryType><currencyCode/><value>2</value></summary><summary><name>telco-and-utility-enquiries-6</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>telco-and-utility-enquiries-12</name><summaryType>count</summaryType><currencyCode/><value>1</value></summary><summary><name>authorised-agents-enquiries-12</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>authorised-agents-enquiries-60</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>directorships-current</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>directorships-previous</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>judgements</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>proprietorships</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>adverse-on-file</name><summaryType/><currencyCode/><value>No</value></summary><summary><name>file-notes</name><summaryType/><currencyCode/><value>No</value></summary><summary><name>known-identities</name><summaryType>count</summaryType><currencyCode/><value>1</value></summary><summary><name>bankruptcies</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>writs-and-summons</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary><summary><name>external-administration-director</name><summaryType>count</summaryType><currencyCode/><value>0</value></summary></summaryData><scoreData><score><scorecardModel>0303</scorecardModel><relativeRisk>2.3</relativeRisk><vedascore1_1Index>4.0863</vedascore1_1Index><applicantOdds>26.9</applicantOdds><contributingFactor><impact>Greatly Decreases Risk</impact><value>Lack of Consumer Adverse Information</value></contributingFactor><contributingFactor><impact>Moderately Decreases Risk</impact><value>Number of Consumer Credit Applications</value></contributingFactor><contributingFactor><impact>Marginally Decreases Risk</impact><value>Individual Shopping Pattern</value></contributingFactor><contributingFactor><impact>Marginally Decreases Risk</impact><value>Current and Historic Credit Type Sought</value></contributingFactor><population><populationOdds>11.9</populationOdds></population><vedaScore>675</vedaScore><percentile>30</percentile><scoreType>VS 1.1 COMMERCIAL + CONSUMER</scoreType></score></scoreData></enquiryReport></Response></cacheEntryData>
<connectorGroup>vedaxml</connectorGroup>
<connectorId>vedascore</connectorId>
<connectorVersion>2014-08-28</connectorVersion>
<request><Request xmlns:ns2="http://com.vedaadvantage/dp3/connectors" xmlns="http://com.vedaadvantage/dp3/connectors/vedaxml/vedascore"><product><name>vedascoreFinancialCommercialPlusConsumer1_1</name><summary>true</summary></product><individual><individualName><familyName>Mohammadinejad</familyName><firstGivenName>Ali</firstGivenName><otherGivenName></otherGivenName></individualName><gender>unknown</gender><dateOfBirth>1982-01-06Z</dateOfBirth><driversLicenceNumber><countryCodes>AU</countryCodes><value>06011982</value></driversLicenceNumber><ns2:address><ns2:addressType>residentialCurrent</ns2:addressType><ns2:unitNumber>3 U</ns2:unitNumber><ns2:streetNumber>43</ns2:streetNumber><ns2:property>43</ns2:property><ns2:streetName>KING EDWARD</ns2:streetName><ns2:streetType>AVE</ns2:streetType><ns2:suburb>ALBION</ns2:suburb><ns2:state>VIC</ns2:state><ns2:postcode>3020</ns2:postcode><ns2:countryCode>AU</ns2:countryCode></ns2:address><role>principal</role></individual><enquiry><accountType><accountType>CR</accountType></accountType><enquiryAmount><currencyCodeType>AUD</currencyCodeType><value>25000</value></enquiryAmount><enquiryType>creditEnquiry</enquiryType></enquiry><customerReference>GoGetta</customerReference></Request></request>
</ns3:CacheEntry>
</ns3:getCacheEntryResponse>
</soap:Body>
</soap:Envelope>
I have used http://xmltocsharp.azurewebsites.net/ to generate my C# classes which look like this:
[XmlRoot(ElementName = "CacheEntry", Namespace = "http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef/IndividualCommercialService")]
public class CacheEntry
{
[XmlElement(ElementName = "cacheEntryData")]
public string CacheEntryData { get; set; }
[XmlElement(ElementName = "connectorGroup")]
public string ConnectorGroup { get; set; }
[XmlElement(ElementName = "connectorId")]
public string ConnectorId { get; set; }
[XmlElement(ElementName = "connectorVersion")]
public string ConnectorVersion { get; set; }
[XmlElement(ElementName = "request")]
public string Request { get; set; }
}
[XmlRoot(ElementName = "getCacheEntryResponse", Namespace = "http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef/IndividualCommercialService")]
public class GetCacheEntryResponse
{
[XmlElement(ElementName = "CacheEntry", Namespace = "http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef/IndividualCommercialService")]
public CacheEntry CacheEntry { get; set; }
[XmlAttribute(AttributeName = "ns3", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns3 { get; set; }
[XmlAttribute(AttributeName = "ns2", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns2 { get; set; }
[XmlAttribute(AttributeName = "ns4", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns4 { get; set; }
[XmlAttribute(AttributeName = "ns5", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns5 { get; set; }
[XmlAttribute(AttributeName = "ns6", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns6 { get; set; }
[XmlAttribute(AttributeName = "ns7", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns7 { get; set; }
[XmlAttribute(AttributeName = "ns8", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns8 { get; set; }
[XmlAttribute(AttributeName = "ns9", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Ns9 { get; set; }
}
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "getCacheEntryResponse", Namespace = "http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef/IndividualCommercialService")]
public GetCacheEntryResponse GetCacheEntryResponse { get; set; }
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "soap", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Soap { get; set; }
}
Here is how I am trying to extract the cacheEntryData field but it is not retrieving the node list (xnList) and it is not returning anything in my foreach statement.
public override void CreateNewOutputRows()
{
string soap_resp = Variables.getCacheEntryRspXML.ToString();
soap_resp = soap_resp.Replace("\"\"", "\"");
System.Windows.Forms.MessageBox.Show(soap_resp);
XmlDocument agv = new XmlDocument();
agv.LoadXml(soap_resp);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(agv.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("ns3", "http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/SilverChef/IndividualCommercialService");
XmlNodeList xnList = agv.SelectNodes("//ns3:CacheEntry", nsmgr);
foreach (XmlNode xn in xnList)
{
var cacheEntryData = xn["ns3:CacheEntry"].InnerText;
System.Windows.Forms.MessageBox.Show(Convert.ToString(cacheEntryData));
}
}
This is very unusual. The code looks like in was html encoded so I had to html decode.
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Net;
namespace ConsoleApplication73
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
string xml = File.ReadAllText(FILENAME);
CreateNewOutputRows(xml);
}
static public void CreateNewOutputRows(string xml)
{
XDocument doc = XDocument.Parse(xml);
XElement cacheEntryData = doc.Descendants().Where(x => x.Name.LocalName == "cacheEntryData").FirstOrDefault();
string cacheEntryDataXml = WebUtility.HtmlDecode(cacheEntryData.ToString());
XElement cacheEntryData2 = XElement.Parse(cacheEntryDataXml);
}
}
}