Create xml structure from string.split

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Create xml structure from string.split



I want to create a xml file from a string that looks like this:


"Node_1/Node_2/Node_3|Node_1/Node_4|Node_1/Node_2/Node_5"



the output should be:


<Node_1>
<Node_2>
<Node_3>
</Node_3>
<Node_5>
</Node_5>
</Node_2>
<Node_4>
</Node_4>
</Node_1>



the string should resemble something like a file path and the nodes in the xml should resemble something like folders. The first "Folder" is allways the same (Node_1) to keep it a valid xml.



Edit: I am trying to combine xml files which contain some Data and the "path"
where the data is supposed to be written into one big xml file.



First i want to create the new xml from these "paths" and then write the data into the created nodes.
So i don't have any structure to work with only the string which is created by combing the "paths" out of the xml files and separating them with "|" so i can split the string into each "path".





"Folder"? If that string represents a folder structure it would be easier to generate XML directly from that structure instead of that string. Otherwise you'll have to parse the string, recreate the tree and then serialize it
– Panagiotis Kanavos
Aug 6 at 8:05






check this similar question stackoverflow.com/questions/14798854/c-xml-adding-new-nodes
– Nitin Sawant
Aug 6 at 9:16




1 Answer
1



As your input is not a standard format (at least non I'm aware of), you have to write your own parser.



I suggest you create an object (tree) first from the string:


class Node

List<Node> Children get;set;



Then you can use XmlSerializer to create the XML.


XmlSerializer


XmlSerializer serializer = XmlSerializer(typeof(Node));
using(TextWriter writer = new StreamWriter(filename))

serializer.Serialize(writer, node1);



https://msdn.microsoft.com/de-de/library/system.xml.serialization.xmlserializer%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS