Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Remove xmlns and select signle node
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Xml; using System.Xml.Linq; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here //Console.WriteLine(xdoc.DocumentElement); XmlDocument xdoc = new XmlDocument(); var sxml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><CalcolaSimulazioneOut><ID_Pratica xmlns=\"http://www.domain.com/peqc/webservices\">12345</ID_Pratica><Tan xmlns=\"http://www.domain.com/peqc/webservices\">7.04</Tan><Montante xmlns=\"http://www.domain.com/peqc/webservices\">9720</Montante><Interessi xmlns=\"http://www.domain.com/peqc/webservices\">981.49</Interessi><Finanziato xmlns=\"http://www.domain.com/peqc/webservices\">8738.51</Finanziato><Commissioni xmlns=\"http://www.domain.com/peqc/webservices\">245.80</Commissioni><SpeseIstruttorie xmlns=\"http://www.domain.com/peqc/webservices\">100</SpeseIstruttorie><SpeseDistribuzione xmlns=\"http://www.domain.com/peqc/webservices\">45.80</SpeseDistribuzione><ImpostaDiBollo xmlns=\"http://www.domain.com/peqc/webservices\">0</ImpostaDiBollo><SpeseDiIncasso xmlns=\"http://www.domain.com/peqc/webservices\">0</SpeseDiIncasso><FondoRischiInpdap xmlns=\"http://www.domain.com/peqc/webservices\">0</FondoRischiInpdap><ImportoDaErogare xmlns=\"http://www.domain.com/peqc/webservices\">8492.71</ImportoDaErogare><Taeg xmlns=\"http://www.domain.com/peqc/webservices\">8.50</Taeg></CalcolaSimulazioneOut>"; xdoc = RemoveXmlns(sxml); Console.WriteLine(xdoc.SelectSingleNode("CalcolaSimulazioneOut/ID_Pratica").InnerText); } public static XmlDocument RemoveXmlns(String xml) { XDocument d = XDocument.Parse(xml); d.Root.Descendants().Attributes().Where(x => x.IsNamespaceDeclaration).Remove(); foreach (var elem in d.Descendants()) elem.Name = elem.Name.LocalName; var xmlDocument = new XmlDocument(); xmlDocument.Load(d.CreateReader()); return xmlDocument; } } }
run
|
edit
|
history
|
help
0
GetDataFromSQLGroups
Using Yield Return to mass copy a Class instance
Fusion
Download a UTF-8 text file, and display the contents.
Reverse Number
Abstract Method Design Pattern in C#
Social
Linked list problem with remove
average and percentage
BankAccount