Something works
This commit is contained in:
parent
06fdcc6d79
commit
a6ddc6f9d2
@ -25,4 +25,29 @@
|
||||
<Step>Serveeri ja naudi</Step>
|
||||
</Steps>
|
||||
</Recipe>
|
||||
<Recipe>
|
||||
<Name>Supp</Name>
|
||||
<Description>
|
||||
Väga hea supp
|
||||
</Description>
|
||||
<Ingredients>
|
||||
<Ingredient>
|
||||
<Name>Porgand</Name>
|
||||
<Amount multiplierPerPortion="2">100</Amount>
|
||||
<Unit>g</Unit>
|
||||
</Ingredient>
|
||||
<Ingredient>
|
||||
<Name>Kartul</Name>
|
||||
<Amount multiplierPerPortion="2">200</Amount>
|
||||
<Unit>g</Unit>
|
||||
</Ingredient>
|
||||
</Ingredients>
|
||||
<Steps>
|
||||
<Step>Koori kartul</Step>
|
||||
<Step>Pese porgand</Step>
|
||||
<Step>Kõik potti keema</Step>
|
||||
<Step>Oota kuni valmis</Step>
|
||||
<Step>Serveeri ja naudi</Step>
|
||||
</Steps>
|
||||
</Recipe>
|
||||
</Recipes>
|
||||
|
@ -1,99 +1,29 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using Microsoft.SqlServer.Server;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace vr21
|
||||
{
|
||||
[XmlRoot("Recipes")]
|
||||
public class Recipes
|
||||
{
|
||||
[XmlElement("Recipe")]
|
||||
public List<Recipe> RecipeList { get; set; }
|
||||
|
||||
public Recipes()
|
||||
{
|
||||
RecipeList = new List<Recipe>();
|
||||
}
|
||||
}
|
||||
|
||||
public class Recipe
|
||||
{
|
||||
[XmlElement("Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[XmlElement("Ingredient")]
|
||||
public List<Ingredient> IngredientsList { get; set; }
|
||||
|
||||
[XmlElement("Step")]
|
||||
public List<string> StepList { get; set; }
|
||||
|
||||
public Recipe()
|
||||
{
|
||||
IngredientsList = new List<Ingredient>();
|
||||
StepList = new List<string>();
|
||||
}
|
||||
|
||||
public Recipe(string name)
|
||||
{
|
||||
Name = name;
|
||||
IngredientsList = new List<Ingredient>();
|
||||
StepList = new List<string>();
|
||||
}
|
||||
|
||||
public Recipe(string name, List<Ingredient> ingredients)
|
||||
{
|
||||
Name = name;
|
||||
IngredientsList = ingredients;
|
||||
StepList = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
public class Ingredient
|
||||
{
|
||||
[XmlElement("Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[XmlElement("Amount")]
|
||||
public int Amount { get; set; }
|
||||
|
||||
public Ingredient(string name)
|
||||
{
|
||||
Name = name;
|
||||
Amount = 1;
|
||||
}
|
||||
|
||||
public Ingredient(string name, int amount)
|
||||
{
|
||||
Name = name;
|
||||
Amount = amount;
|
||||
}
|
||||
}
|
||||
class Program
|
||||
{
|
||||
private static string _xmllocation = @"..\..\..\XMLRecipe.xml";
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var recipes = new Recipes();
|
||||
recipes.RecipeList.Add(new Recipe("Supp"));
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(Recipes));
|
||||
writeReceipesInformation();
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
var xml = "";
|
||||
|
||||
using (var sww = new StringWriter())
|
||||
static void writeReceipesInformation()
|
||||
{
|
||||
using (XmlWriter writer = XmlWriter.Create(sww))
|
||||
XDocument xdoc = XDocument.Load(_xmllocation);
|
||||
var allReceipes = xdoc.Descendants("Recipe");
|
||||
foreach (var receipe in allReceipes)
|
||||
{
|
||||
serializer.Serialize(writer, recipes);
|
||||
xml = sww.ToString(); // Your XML
|
||||
Console.WriteLine(receipe.Element("Name").Value);
|
||||
foreach (var ingredient in receipe.Element("Ingredients").Elements())
|
||||
{
|
||||
Console.WriteLine($" {ingredient.Element("Name").Value}: {ingredient.Element("Amount").Value}{ingredient.Element("Unit").Value}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine(xml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2970
vr21/XMLRecipe.Designer.cs
generated
2970
vr21/XMLRecipe.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
|
@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xs:schema id="Recipes" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xs:element name="Recipes" msdata:IsDataSet="true" msdata:Locale="en-US">
|
||||
<xs:complexType>
|
||||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:element name="Recipe">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Name" type="xs:string" minOccurs="0" />
|
||||
<xs:element name="Description" type="xs:string" minOccurs="0" />
|
||||
<xs:element name="Ingredients" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Ingredient" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Name" type="xs:string" minOccurs="0" />
|
||||
<xs:element name="Unit" type="xs:string" minOccurs="0" />
|
||||
<xs:element name="Amount" nillable="true" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent msdata:ColumnName="Amount_Text" msdata:Ordinal="1">
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="multiplierPerPortion" type="xs:string" />
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="Steps" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Step" nillable="true" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent msdata:ColumnName="Step_Text" msdata:Ordinal="0">
|
||||
<xs:extension base="xs:string">
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
@ -1 +0,0 @@
|
||||
|
@ -45,25 +45,9 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="XMLRecipe.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>XMLRecipe.xsd</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="XMLRecipe.xsc">
|
||||
<DependentUpon>XMLRecipe.xsd</DependentUpon>
|
||||
</None>
|
||||
<None Include="XMLRecipe.xsd">
|
||||
<Generator>MSDataSetGenerator</Generator>
|
||||
<LastGenOutput>XMLRecipe.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="XMLRecipe.xss">
|
||||
<DependentUpon>XMLRecipe.xsd</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
Loading…
Reference in New Issue
Block a user