C
C#7mo ago
Hlen_42

Help to convert .xml

I created a program that tries to modify the structure of a long xml. according to a short one and the result should be like this: <SHOP> <SHOPITEM> <VAT>21</VAT> </SHOPITEM> <SHOPITEM> <VAT>21</VAT> </SHOPITEM> <SHOPITEM> <VAT>21</VAT> </SHOPITEM> <CODE>KT1</CODE> <CODE>KT3</CODE> <CODE>GXLP011</CODE> </SHOP> Unfortunately, it doesn't convert correctly. Do you know where the error is and how can I fix it?
4 Replies
Joschi
Joschi7mo ago
If you want to transform XML into another format you really got two option. Either you deserialize it into C# objects, transform those and serialize again in the correct format. Or you take a look at XSLT transformers, which is a language used to transform XML. https://en.wikipedia.org/wiki/XSLT XSLT transformations are supported in C# and there are a lot of ressources on how to do it.
XSLT
XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG. Support for JSON and plain-text ...
Hlen_42
Hlen_42OP7mo ago
@Joschi I'm sorry, but I don't have time to learn new concepts. I've been given homework and I'm trying to figure it out. I finally managed to convert the .xml from the structure, but I can't keep the data with it and in the elements. Could you take a look at this part of the code? The problem is probably in this method: MoveXmlElementsBasedOnTreeView, because the whole .xml is modified according to the treeview structure, but I can't figure out how to keep the content in the elements. ITS ALL EMPTY <SHOP> <SHOPITEM> <CODE> </CODE> <NAME> </NAME> <PLU> </PLU> <VAT> </VAT> <CURRENCY> </CURRENCY> <PRICE_VAT> </PRICE_VAT> </SHOPITEM> <SHOPITEM> <CODE> </CODE> <NAME> </NAME> <PLU> </PLU> <VAT> </VAT> <CURRENCY> </CURRENCY> <PRICE_VAT> </PRICE_VAT> </SHOPITEM> </SHOP>
Joschi
Joschi7mo ago
$code
MODiX
MODiX7mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Want results from more Discord servers?
Add your server