Filtering by higher nodes attributes linq - c#

I am trying to serialize and insert a new created object into a specific child node of an XDocument. I've managed to accomplish this but my code seems smelly.
How can I test against a higher nodes attribute value without chaining through the Parent property like I have done below?
XDocument xdoc = XDocument.Load(path);
var elements = (
from doc in xdoc.Descendants("Unit")
where doc.Parent.Parent.Attribute("name").Value == _UnitTypeName &&
doc.Parent.Parent.Parent.Parent.Attribute("name").Value == _UnitCategoryN
doc.Parent.Parent.Parent.Parent.Parent.Parent.Attribute("name").Value ==
select doc
);
foreach (var element in elements)
{
Unit unit =
new Unit
{
Armour = _Armour,
Attacks = _Attacks,
BallisticSkill = _BallisticSkill,
Composition = _Composition,
DedicatedTransport = _DedicatedTransport,
Initiative = _Initiative,
Leadership = _Leadership,
Options = _Options,
SaveThrow = _SaveThrow,
SpecialRules = _SpecialRules,
Strength = _Strength,
Toughness = _Toughness,
UnitName = _UnitName,
Weapons = _Weapons,
WeaponSkill = _WeaponSkill,
Wounds = _Wounds,
Points = _Points
};
XmlSerializer serializer = new XmlSerializer(typeof(Unit));
using (var stream = new MemoryStream())
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(stream, unit, ns);
stream.Position = 0;
//using (XmlReader reader = XmlReader.Create(stream))
//{
// XElement xe = XElement.Load(reader);
XElement xe = XElement.Load(#"C:\Test\tempfile.xml"); // For some reason loading via MemoryStream messes with xml formatting
element.AddBeforeSelf(xe);
//}
}
break;
}
xdoc.Save(path);
This is the structure of the XML Document:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfArmy>
<Army name="Tyranid">
<unit-category>
<UnitCategory name="Troops">
<unit-type>
<UnitType name="Infantry">
<unit>
<Unit points="5" name="Hornmagant" composition="20" weapon-skill="3" ballistic-skill="100" strength="3" toughness="4" wounds="1" initiative="3" attacks="3" leadership="5" saving-throw="6+" armour="Chitin" weapons="Many" special-rules="None" dedicated-transport="No" options="8">
<Amount>0</Amount>
</Unit>
<Unit points="5" name="Termagant" composition="20" weapon-skill="3" ballistic-skill="100" strength="3" toughness="4" wounds="1" initiative="3" attacks="3" leadership="5" saving-throw="6+" armour="Chitin" weapons="Many" special-rules="None" dedicated-transport="No" options="8">
<Amount>0</Amount>
</Unit>
</unit>
</UnitType>
</unit-type>
</UnitCategory>
</unit-category>
</Army>
</ArrayOfArmy>

You can use compound from clauses, which is similar to using nested foreach loops:
var elements = (
from army in xdoc.Descendants("Army")
where army.Attribute("name").Value == _ArmyName
from unitCategory in army.Descendants("UnitCategory")
where unitCategory.Attribute("name").Value == _UnitCategoryName
from unitType in unitCategory.Descendants("UnitType")
where unitType.Attribute("name").Value == _UnitTypeName
from unit in unitType.Descendants("Unit")
select unit
);
Note: the method syntax equivalent is SelectMany().

Related

Reading XML Response from envelope event notification

In my MakeEnvelope method, I have added an event notification as follows:
var en = new EventNotification
{
Url = "<Listener URL>",
LoggingEnabled = "true",
RequireAcknowledgment = "true",
EnvelopeEvents = new List<EnvelopeEvent>
{
new EnvelopeEvent
{
EnvelopeEventStatusCode = "Completed",
IncludeDocuments = "true"
},
new EnvelopeEvent
{
EnvelopeEventStatusCode = "Delivered",
IncludeDocuments = "false"
},
new EnvelopeEvent
{
EnvelopeEventStatusCode = "Sent",
IncludeDocuments = "false"
}
}
};
envelopeDefinition.EventNotification = en;
I get the following XML response (I removed the Names and Emails, and changed the Guids):
<?xml version="1.0" encoding="utf-8"?><DocuSignEnvelopeInformation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.docusign.net/API/3.0"><EnvelopeStatus><RecipientStatuses><RecipientStatus><Type>Signer</Type><Email>someEmail#email.com</Email><UserName>SomeUserName</UserName><RoutingOrder>1</RoutingOrder><Sent>2021-04-28T14:14:41.163</Sent><Delivered>2021-04-28T14:14:54.997</Delivered><Signed>2021-04-28T14:14:59.73</Signed><DeclineReason xsi:nil="true" /><Status>Completed</Status><RecipientIPAddress>IP Address</RecipientIPAddress><ClientUserId>The ClientId</ClientUserId><CustomFields /><TabStatuses><TabStatus><TabType>SignHere</TabType><Status>Signed</Status><XPosition>938</XPosition><YPosition>1169</YPosition><TabLabel>Sign Here</TabLabel><TabName>SignHere</TabName><TabValue /><DocumentID>3</DocumentID><PageNumber>1</PageNumber></TabStatus></TabStatuses><AccountStatus>Active</AccountStatus><RecipientId>f571daaf-cd2c-4fge-a72e-d32277929305</RecipientId></RecipientStatus><RecipientStatus><Type>Signer</Type><Email>anotherEmail.Email.com</Email><UserName>Another Name</UserName><RoutingOrder>1</RoutingOrder><Sent>2021-04-28T14:14:41.503</Sent><DeclineReason xsi:nil="true" /><Status>Sent</Status><RecipientIPAddress /><CustomFields /><TabStatuses><TabStatus><TabType>SignHere</TabType><Status>Active</Status><XPosition>196</XPosition><YPosition>1169</YPosition><TabLabel>Sign Here</TabLabel><TabName>SignHere</TabName><TabValue /><DocumentID>3</DocumentID><PageNumber>1</PageNumber></TabStatus></TabStatuses><AccountStatus>Active</AccountStatus><RecipientId>1eb9d346-33ae-4444-b5f1-be30f8bcf041</RecipientId></RecipientStatus></RecipientStatuses><TimeGenerated>2021-04-28T14:15:03.3011225</TimeGenerated><EnvelopeID>3c9281c7-3345-44ac-9c4f-3d39274c49f4</EnvelopeID><Subject>Please sign this document</Subject><UserName>User Name</UserName><Email>Users Email Address Here</Email><Status>Sent</Status><Created>2021-04-28T14:14:40.41</Created><Sent>2021-04-28T14:14:41.557</Sent><ACStatus>Original</ACStatus><ACStatusDate>2021-04-28T14:14:40.41</ACStatusDate><ACHolder>Account Holders name</ACHolder><ACHolderEmail>Account Holders Email</ACHolderEmail><ACHolderLocation>DocuSign</ACHolderLocation><SigningLocation>Online</SigningLocation><SenderIPAddress>Senders IP Address</SenderIPAddress><EnvelopePDFHash /><CustomFields /><AutoNavigation>true</AutoNavigation><EnvelopeIdStamping>true</EnvelopeIdStamping><AuthoritativeCopy>false</AuthoritativeCopy><DocumentStatuses><DocumentStatus><ID>3</ID><Name>PG Document</Name><TemplateName /><Sequence>1</Sequence></DocumentStatus></DocumentStatuses></EnvelopeStatus></DocuSignEnvelopeInformation>
I was having issues parsing the response, so I created a console application to parse the xml string, and using the response xml shown above. The following is the code that I used to parse.
static void Main(string[] args)
{
string strXML = GetXML();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXML);
string xpath = "DocuSignEnvelopeInformation/EnvelopeStatus";
var nodes = xmlDoc.SelectNodes(xpath);
foreach (XmlNode childrenNode in nodes)
{
Console.WriteLine(childrenNode.SelectSingleNode("//status").Value);
}
Console.Read();
}
nodes is always empty.
What am I missing here?
Thank you in advance.
I was able to get it to work by using the namespace it was using.
var ns = new XmlNamespaceManager(xmlDoc.NameTable);
ns.AddNamespace("docusign", "http://www.docusign.net/API/3.0");
var envelopeId = xmlDoc.SelectSingleNode("//docusign:EnvelopeID", ns);
var status = xmlDoc.SelectSingleNode("//docusign:Status", ns);
I changed the method and I am able to get the values:
Request.InputStream.Position = 0;
var xmlDoc = new XmlDocument();
xmlDoc.Load(Request.InputStream);
var ns = new XmlNamespaceManager(xmlDoc.NameTable);
ns.AddNamespace("docusign", "http://www.docusign.net/API/3.0");
var envelopeId = xmlDoc.SelectSingleNode("//docusign:EnvelopeID", ns);
var status = xmlDoc.SelectSingleNode("//docusign:EnvelopeStatus/docusign:Status", ns);
if (envelopeId == null || String.IsNullOrEmpty(envelopeId.InnerText) || status == null || string.IsNullOrEmpty(status.InnerText)) return;
if (status.InnerText.ToLower() == "completed")
{
// Update the Document Status
var extra = _uow.JobExtraRepository.GetByEnvelopeId(envelopeId.InnerText);
extra.StatusId = (int)ExtraJobStatus.Completed;
Save();
var docBytes = xmlDoc.SelectSingleNode("//docusign:docBytes", ns);
}

How to hold more than one values in XML element?

xWaarde.Value is overriding with new values and flushing old values.
how to stored multiple values in Xelement.
private XElement[] AddCoordinatenList(XElement childElements)
{
XmlNode xmlCoordinatenNode = Utility.GetMappingValues(Constants.BMCoordinaten, ConnectionType.BM);
XmlNode xWaardeNode = Utility.GetMappingValues(Constants.BMXwaarde, ConnectionType.BM);
XmlNode yWaardeNode = Utility.GetMappingValues(Constants.BMYwaarde, ConnectionType.BM);
XmlNode CoordinateX = Utility.GetMappingValues(Constants.XCoordinate, ConnectionType.BM);
XmlNode CoordinateY = Utility.GetMappingValues(Constants.YCoordinate, ConnectionType.BM);
var coordinatenList = from document in childElements.DescendantsAndSelf() where document.Name.LocalName == xmlCoordinatenNode.Name select document;
List<XElement> xcoordinatenList = new List<XElement>();
XElement xWaarde = new XElement(CoordinateX.Name);
XElement yWaarde = new XElement(CoordinateY.Name);
if (coordinatenList.Count() > 0)
{
foreach (XElement element in coordinatenList.Descendants())
{
if (element.Name.LocalName == xWaardeNode.Name)
{
xWaarde.Value = element.Value;
}
if (element.Name.LocalName == yWaardeNode.Name)
{
yWaarde.Value = element.Value;
}
}
}
return xcoordinatenList.ToArray();
}
It's not possible. Use Attributes:
XAttribute attribute = new XAttribute("name1", <value>);
element.Add(attribute);
attribute = new XAttribute("name2", <value>);
element.Add(attribute);
You can also add a list of child elements or add all strings as one string, separated by a comma for instance.

Append an existing child to the new child?

I have a xml file as:-
<Data>
<Caption>
</Caption>
</Data>
I added a new child CData in the the following code
foreach (XmlNode item in childNode.ChildNodes)
{
if (item.Name == "Data")
{
XmlCDataSection CData;
CData = xml2.CreateCDataSection("All Jane Austen novels 25% off starting 3/23!");
item.InsertBefore(CData, item.FirstChild);
foreach (XmlNode itemC in item.ChildNodes)
{
if (itemC.Name == "Caption")
{
XmlElement getTemplateID = xml2.CreateElement("TempalteID");
getTemplateID.InnerText = "10010";
itemC.AppendChild(getTemplateID);
//if (OptionsData[0].Key == "NoChilds")
//{
// XmlElement Getnochild = itemDoc.CreateElement("CaptionOptions");
// Getnochild.InnerText = "";
// itemC.AppendChild(Getnochild);
//}
//else
//{
XmlNode elemCap = xml2.CreateNode(XmlNodeType.Element, "CaptionOptions", null);
itemC.AppendChild(elemCap);
XmlElement Getelem1 = xml2.CreateElement("CaptionField");
elemCap.AppendChild(Getelem1);
XmlElement elem2 = xml2.CreateElement("FieldID");
XmlElement elem3 = xml2.CreateElement("FieldID");
elem2.InnerText = "#FieldId1";
elem3.InnerText = "#FieldId2";
XmlElement elem4 = xml2.CreateElement("TextString");
XmlElement elem5 = xml2.CreateElement("TextString");
elem4.InnerText = "#TextString1";
elem5.InnerText = "#TextString2";
Getelem1.AppendChild(elem2);
Getelem1.AppendChild(elem4);
Getelem1.AppendChild(elem3);
Getelem1.AppendChild(elem5);
//}
}
}
}
}
Now my final xml is coming as
<Data>
<![CDATA[All Jane Austen novels 25% off starting 3/23!]]>
<Caption>
<TempalteID>10010</TempalteID>
<CaptionOptions><CaptionField>
<FieldID>#FieldId1</FieldID>
<TextString>#TextString1</TextString>
<FieldID>#FieldId2</FieldID>
<TextString>#TextString2</TextString>
</CaptionField></CaptionOptions>
</Caption>
</Data>
But I want to make it as the following way....
<Data><![CDATA[<Caption xmlns="http://www.iin.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.happy.xsd">
<TemplateID>T000114-NOW</TemplateID>
<CaptionOptions>
<CaptionField>
<FieldID>NOW1</FieldID>
<TextString>"Ep 01"</TextString>
</CaptionField>
<CaptionField>
<FieldID>NOW2</FieldID>
<TextString>""</TextString>
</CaptionField>
</CaptionOptions>
</Caption>]]>
</Data>
So as you can see I basically wanted my newly added child CData to make <Caption> as it's child. So basically I want to create a child and make an existing child as it's child.(But I don't think I would still get the same format?")
How to do it?
Using xml Linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Runtime.InteropServices;
namespace ConsoleApplication23
{
class Program
{
static void Main(string[] args)
{
string xml = "<Data><Caption xmlns=\"http://www.iin.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.happy.xsd\"/></Data>";
XDocument doc = XDocument.Parse(xml);
XElement caption = doc.Descendants("Data").FirstOrDefault();
caption.Add(new XElement("TemplateID","T000114-NOW"));
XElement options = new XElement("CaptionOptions");
caption.Add(options);
foreach (Field field in Field.fields)
{
XElement newField = new XElement("CaptionField", new object[] { new XElement("FieldID", field.ID), new XElement("TextString", field.text)});
options.Add(newField);
}
}
}
public class Field
{
public static List<Field> fields = new List<Field>() {
new Field() { ID = "NOW1", text = "Ep 01"},
new Field() { ID = "Ep 01", text = ""}
};
public string ID { get; set; }
public string text { get; set; }
}
}
If I understand right, what you want to do is storing XML data in CDATA element. I want to remind you, that this is not what CDATA was intended to be used for, but here is example how to do that:
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
//Add the new node to the document.
XmlElement root = doc.DocumentElement;
XmlCDataSection CData;
CData = doc.CreateCDataSection(root.InnerXml);
root.RemoveAll();
root.AppendChild(CData);
doc.Save(Console.Out);

read xml document and update all fields c#

i'm trying to read xml file and update all it's value my xml was
<adf>
<prospect>
<requestdate>2015-10-29 07-38-22</requestdate>
<id sequence="1" source="admin.ss.com">admin.ss.com</id>
<vehicle interest="buy" status="">
<id sequence="1" source=""></id>
<year></year>
<make></make>
<model>camry</model>
<vin></vin>
<stock></stock>
<trim></trim>
</vehicle>
<customer>
<contact primarycontact="1">
<name part="first">Jessica</name>
<name part="last">Sonntag</name>
<email>js#test.com</email>
<phone type="phone" time="day">555-585-5555</phone>
<address>
<street line="1"></street>
<city></city>
<regioncode></regioncode>
<postalcode></postalcode>
<country></country>
</address>
</contact>
<comments>Vehicle Year: 2011 Comments: </comments>
</customer>
<provider>
<name part="full">ST</name>
<service> Engine Marketing</service>
<phone>1-866-572-3952</phone>
</provider>
</prospect>
</adf>
so i select node like below
var items = (from item in xmlDoc.Descendants("requestdate")
select item).ToList();
then i can update only requestdata tag value so do i have to repeat same for all tags or is there any good way to accomplish this.
Regards
There is an easy way to do this. This one is a hidden gem. Most people may not know this. This feature came in VS2013 and it's called "Paste XML as Classes."
Save your xml (Ex: MyXml.XML)
Create a new Console project
Open the Xml in Visual studio
Copy All contents of the xml (Ctl+A, Ctl + C)
Add a new class to your project. You can give any name you like.
Go to Edit>Paste Special>Paste XML as classes.
Add another class to your project. Then add below two methods to that class.
public static string Serialise<T>(T serialisableObject)
{
var doc = new XmlDocument();
using (var stream = new StringWriter())
{
var settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
XmlWriter xmlWriter = XmlWriter.Create(stream, settings);
var ns = new XmlSerializerNamespaces();
ns.Add("", "");
var xmlSerializer = new XmlSerializer(typeof(T));
xmlSerializer.Serialize(xmlWriter, serialisableObject, ns);
doc.LoadXml(stream.ToString());
}
return doc.InnerXml;
}
public static T Deserialise<T>(string xml)
{
T list;
using (var reader = new StringReader(xml))
{
var serialiser = new XmlSerializer(typeof(T));
list = (T)serialiser.Deserialize(reader);
}
return list;
}
Then in your console applications Main method; add this.
var myObj = new adf();
myObj.prospect = new adfProspect();
myObj.prospect.customer = new adfProspectCustomer(){comments = "dgsrtetetete"};
//populate all fields.....
var xml = MySerializer.Serialise(myObj);
File.WriteAllText(#"C:\myNewXml.xml", xml);
That's it. Same way now you can deserialise an xml object in to your class.
Try the XmlSerializer class: https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(v=vs.110).aspx If you serialize/deserialize the xml then up dating is trivial.
If you wanted to change every phone number to "0123456789" you could do something like:
var xDoc = XDocument.Load("document.xml");
var results = from phone in xDoc.Descendants("phone") select phone;
foreach (XElement result in results)
{
element.SetValue("0123456789");
}
i have came up with solution with support two extension method i'm iterating all nodes and update.(since my xml is not too big or complicated this one would be a good solution)
with help of these two extension methods
public static void IterateThroughAllNodes(this XmlDocument doc, Action<XmlNode> elementVisitor)
{
if (doc != null && elementVisitor != null)
{
foreach (XmlNode node in doc.ChildNodes)
{
DoIterateNode(node, elementVisitor);
}
}
}
public static void IterateThrough(this XmlNodeList nodes, Action<XmlNode> elementVisitor)
{
if (nodes != null && elementVisitor != null)
{
foreach (XmlNode node in nodes)
{
DoIterateNode(node, elementVisitor);
}
}
}
private static void DoIterateNode(XmlNode node, Action<XmlNode> elementVisitor)
{
elementVisitor(node);
foreach (XmlNode childNode in node.ChildNodes)
{
DoIterateNode(childNode, elementVisitor);
}
}
then i can update my xml nodes as below
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/xmlmail.xml"));
var email = new XmlEmail();
doc.IterateThroughAllNodes(
delegate(XmlNode node)
{
if (node.Name.Equals("requestdate"))
node.InnerText= email.RequestDate.ToLongDateString();
if (node.Name.Equals("vehicle"))
{
XmlNodeList childs = node.ChildNodes;
childs.IterateThrough(delegate(XmlNode vnode)
{
if (vnode.Name.Equals("id"))
vnode.InnerText= email.VehicleId.ToString();
if (vnode.Name.Equals("year"))
vnode.InnerText= email.Year.ToString();
if (vnode.Name.Equals("make"))
vnode.InnerText= email.Make;
if (vnode.Name.Equals("model"))
vnode.InnerText= email.Model;
if (vnode.Name.Equals("vin"))
vnode.InnerText= email.Vin;
if (vnode.Name.Equals("trim"))
vnode.InnerText = email.Trim;
});
}
if (node.Name.Equals("customer"))
{
XmlNodeList childs = node.ChildNodes;
childs.IterateThrough(delegate(XmlNode vnode)
{
if (vnode.Attributes != null && (vnode.Name.Equals("name") && vnode.Attributes["part"].Value.Equals("first")))
vnode.InnerText= email.FirstName;
if (vnode.Attributes != null && (vnode.Name.Equals("name") && vnode.Attributes["part"].Value.Equals("last")))
vnode.InnerText= email.LastName;
if (vnode.Name.Equals("email"))
vnode.InnerText= email.Email;
if (vnode.Name.Equals("phone"))
vnode.InnerText= email.Phone;
if (vnode.Name.Equals("comments"))
vnode.InnerText= email.Comments;
if (vnode.Name.Equals("address"))
{
XmlNodeList addresschilds = vnode.ChildNodes;
addresschilds.IterateThrough(delegate(XmlNode anode)
{
if (anode.Name.Equals("street"))
anode.InnerText= email.Street;
if (anode.Name.Equals("city"))
anode.InnerText= email.City;
if (anode.Name.Equals("phone"))
anode.InnerText= email.Phone;
if (anode.Name.Equals("regioncode"))
anode.InnerText= email.RegionCode;
if (anode.Name.Equals("postalcode"))
anode.InnerText= email.Postalode;
if (anode.Name.Equals("country"))
anode.InnerText= email.Country;
});
}
});
}
});

Load from XML to Observable collection

I am having trouble while load xml file into Observable Collection.
My XML look like
<?xml version="1.0" encoding="utf-8"?>
<Stock>
<Assortment>
<Item>Адельфан - эзидрекс таб №10</Item>
<Quantity>89</Quantity>
<Price>3.0000</Price>
<Summ>267</Summ>
<Price1>3.0000</Price1>
<Summ1>267</Summ1>
<ValidDate>01.01.2031</ValidDate>
<Manufacturer>КРКА</Manufacturer>
</Assortment>
<Assortment>
<Item>Адельфан - эзидрекс таб №10</Item>
<Quantity>8</Quantity>
<Price>3.0000</Price>
<Summ>24</Summ>
<Price1>3.0000</Price1>
<Summ1>24</Summ1>
<ValidDate>01.01.2019</ValidDate>
<Manufacturer>КРКА</Manufacturer>
</Assortment>
</Stock>
And my code which I tried is this.
XDocument xml = XDocument.Load(filename);
foreach (XElement xe in xml.Elements("Assortment"))
{
_dummyCollection1.Add(new DummyClass1()
{
Наименование = xe.Element("Item").Value,
Количество = xe.Element("Quantity").Value,
Цена = xe.Element("Price").Value,
Сумма = xe.Element("Summ").Value,
Цена1 = xe.Element("Price1").Value,
Сумма1 = xe.Element("Summ1").Value,
Срокгодности = xe.Element("ValidDate").Value,
Производитель = xe.Element("Manufacturer").Value
});
}
BuyDataGrid.ItemsSource = _dummyCollection1;
I am getting empty DataGrid. How to pass xml in to Observable Collection?
I found how to do it, in case if someone need;
XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("Assortment");
foreach (XmlNode node in nodes)
{
_dummyCollection1.Add(new DummyClass1()
{
Наименование = node["Item"].InnerText,
Количество = node["Quantity"].InnerText,
Цена = node["Price"].InnerText,
Сумма = node["Summ"].InnerText,
Цена1 = node["Price1"].InnerText,
Сумма1 = node["Summ1"].InnerText,
Срокгодности = node["ValidDate"].InnerText,
Производитель = node["Manufacturer"].InnerText
});
}
BuyDataGrid.ItemsSource = _dummyCollection1;
Your class which you plan to use as an object for the ObservableCollection collection must implement INotifyPropertyChanged
this is my answer with an example how to populate model for dataGrid
example

Categories