Something works

This commit is contained in:
Arti Zirk 2017-02-01 17:21:58 +02:00
parent 06fdcc6d79
commit a6ddc6f9d2
7 changed files with 39 additions and 3126 deletions

View File

@ -25,4 +25,29 @@
<Step>Serveeri ja naudi</Step> <Step>Serveeri ja naudi</Step>
</Steps> </Steps>
</Recipe> </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> </Recipes>

View File

@ -1,99 +1,29 @@
using System; using System;
using System.Collections; using System.Xml.Linq;
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;
namespace vr21 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 class Program
{ {
private static string _xmllocation = @"..\..\..\XMLRecipe.xml";
static void Main(string[] args) static void Main(string[] args)
{ {
var recipes = new Recipes(); writeReceipesInformation();
recipes.RecipeList.Add(new Recipe("Supp")); Console.ReadKey();
XmlSerializer serializer = new XmlSerializer(typeof(Recipes)); }
var xml = ""; static void writeReceipesInformation()
using (var sww = new StringWriter())
{ {
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); Console.WriteLine(receipe.Element("Name").Value);
xml = sww.ToString(); // Your XML 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); }
}
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@


View File

@ -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>

View File

@ -1 +0,0 @@


View File

@ -45,25 +45,9 @@
<ItemGroup> <ItemGroup>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XMLRecipe.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>XMLRecipe.xsd</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <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> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.