Give attribute to Node in xml page

evetCadep

New Member
I have a Dataset that i turn into a xml file, I can populate my dataset file i cant add attributes to all the nodes correctly.My Xml file is posted below:I need to add the attribute mod and its value to the nodes, Photos, VoiceNotes, FieldNotes. \[code\]<?xml version="1.0" encoding="utf-8"?><FormData Platform="Android" PlatformVersion="73" Version="488" DataVersion="1" Description="Investec - Res" FormId="d617a5e8-b49b-4640-9734-bc7a2bf05691" FileId="e64f4839-012f-43cd-a292-5c7ce14ed0da" EncryptionVerification="" CreatedBy="Shaunm" EditedBy="Shaunm"> <FieldData> <property_details_gps_location IncludeInPDFExport="Yes" Mod="20010101010101">-26.163111, 28.044954</property_details_gps_location> <property_details_address_address1 IncludeInPDFExport="Yes" Mod="20010101010101">12 ALDSWOLD</property_details_address_address1> <property_details_address_address2 IncludeInPDFExport="Yes" Mod="20010101010101">SAXONWOLD</property_details_address_address2> <property_details_address_city IncludeInPDFExport="Yes" Mod="20010101010101">CITY OF JOHANNESBURG</property_details_address_city> <property_details_address_state IncludeInPDFExport="Yes" Mod="20010101010101">GAUTENG</property_details_address_state> <property_details_locality_map IncludeInPDFExport="Yes" Mod="20010101010101">c88a30e6-3473-4e07-8962-b033722b3cd5.jpg</property_details_locality_map> <property_details_type_of_ownership IncludeInPDFExport="Yes" Mod="20010101010101">Freehold</property_details_type_of_ownership> <property_details_area_of_site IncludeInPDFExport="Yes" Mod="20010101010101">2023</property_details_area_of_site> <property_description_erf_number IncludeInPDFExport="Yes" Mod="20010101010101">409</property_description_erf_number> <title_deed__municipal_information_text_box_2 IncludeInPDFExport="Yes" Mod="20010101010101">5700000</title_deed__municipal_information_text_box_2> <title_deed__municipal_information__2 IncludeInPDFExport="Yes" Mod="20010101010101">20111110</title_deed__municipal_information__2> <title_deed__municipal_information_text_box_3 IncludeInPDFExport="Yes" Mod="20010101010101">, 3380000</title_deed__municipal_information_text_box_3> </FieldData> <CompSales> <Erf_x0020_Number>51</Erf_x0020_Number> <Portion_x0020_Number>0</Portion_x0020_Number> <Number>42</Number> <Street>BRISTOL</Street> <Town_x002F_City>SAXONWOLD</Town_x002F_City> <Sale_x0020_Date>20120904</Sale_x0020_Date> <Sale_x0020_Price>6250000</Sale_x0020_Price> <Stand_x0020_Size>2024</Stand_x0020_Size> </CompSales> <Photos></Photos> <FeildNotes></FieldNotes> <VoiceNotes></VoiceNotes></FormData>\[/code\]So far this is how i have managed to add attributes to the other nodes, But i cant get this right for Photos and FiledNotes.\[code\]XDocument doc = XDocument.Parse(myds.GetXml()); doc.Root.Name = "FormData"; doc.Root.Add(new XAttribute("Platform", "Android")); doc.Root.Add(new XAttribute("PlatformVersion", "73")); doc.Root.Add(new XAttribute("Version", "488")); doc.Root.Add(new XAttribute("DataVersion", "1")); doc.Root.Add(new XAttribute("Description", "Investec - Res")); doc.Root.Add(new XAttribute("FormId", "d617a5e8-b49b-4640-9734-bc7a2bf05691")); doc.Root.Add(new XAttribute("FileId", Guid)); doc.Root.Add(new XAttribute("EncryptionVerification", "")); doc.Root.Add(new XAttribute("CreatedBy", "Shaunm")); doc.Root.Add(new XAttribute("EditedBy", "Shaunm")); //XmlNodeList dataNodes = doc."//FieldData"); foreach (XElement element in doc.Root.Element("FieldData").Descendants()) { element.Add(new XAttribute("IncludeInPDFExport", "Yes")); element.Add(new XAttribute("Mod", "20010101010101")); }\[/code\]
 
Back
Top