This is a personal project to get started using RavenDB.
I have been using a mxing program for years whose track data are stored in a xml file. The structure is as follow:
<Song attribute="" attribute="">
<node1 attribute="" />
<node2 attribute="" attribute="" />
<node3 attribute="" attribute="" attribute="" />
<node4 attribute="" attribute="" />
<node5 attribute="" />
</Song>
<Song attribute="" attribute="">
<node1 attribute="" />
<node2 attribute="" />
<node3 attribute="" />
<node4 attribute="" attribute="" />
</Song>
I'd like to manipulate the data (CRUD and other niceties). After having fun, I'd like to save everything into ravenDB and then in a new xml file. As the data are xml nodes, I think it is best to import all the nodes and its content into RavenDB.
To make the design decouple from the schema, I plan to make at least 2 POCO:
DAL : SongRecord POCO whose properties are those from a typical node
BL : Song POCO more business oriented
What should I do?
JSON.NET offers to serialize/deserialize xml to json and vice versa. Once the xml is serialized into json, I can store it into RavenDB.
My BL communicates with the DAL that queries against RavenDB.
After a while I want to persist everything into the db and then export everything into a new xml file, whose schema is the one I mentionned above.
What do you think about it? Is there something wrong? What's best instead? Remember it is a pet project to learn RavenDB.
Doesn't RavenDB handle the serialization back and forth to JSON? All you should have to handle is getting your POCOs back and forth to the XML format for the mixer program. Everywhere else, leave them as POCOs.
Related
Currently I am working on generate a form (WinForm) programmatically according to the given format file. This feature is used for generating forms like product specifications.
The given format file is a text file, its extension is unknown yet, it could be .txt. This format file might change in the future according to the needs, for now, it looks like:
[Hardware]
[Voltage]
[Range]
[Accuracy]
[Current]
[Range]
[Time]
[Precision]
[Software]
[Set up]
[A]
[B]
[C]
[Require]
[E]
[F]
...
And my program should read this format file and generate a form accordingly, like:
This form would later be filled with data from a given Excel file, but I can worry about this part later, for now I only need to worry about how to read from the format file and generate a form.
Any tip would be super helpful. Thank you in advance!
Edit 1: the format file can be anything, I am using .xml file for the format now:
<regionList>
<region id="1">
<regionName>Hardware</regionName>
<modules>
<module1>Voltage</module1>
<components>
<component1>Range</component1>
<component2>Accuracy</component2>
</components>
<module2>Current</module2>
<components>
<component1>Range</component1>
<component2>Time</component2>
<component3>Precision</component3>
</components>
</modules>
<\region>
<region id="2">
<regionName>Software</regionName>
<modules>
<module1>Set Up</module1>
<components>
<component1>A</component1>
<component2>B</component2>
<component3>C</component3>
</components>
<module2>Require</module2>
<components>
<component1>D</component1>
<component2>E</component2>
</components>
</modules>
<\region>
...
<\regionList>
I have following XML. I am trying to generate C# Classes using svcutil. I understand that there are other tools (like Visual Studio Paste Special and XML2CSharp) – but I need to see how svcutil is generating it.
<?xml version="1.0"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" templateId="2.16.840.1.113883.3.27.1776">
<title>Gc test Consultation Note</title>
<effectiveTime value="20000407"/>
<component>
<StructuredBody>
<component>
<section>
<code code="10164-2" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/>
<title>History of Present Illness</title>
<text>Test patient is a 67 year old male referred for further asthma management. Onset of asthma in his
<content revised="delete">twenties</content>
<content revised="insert">teens</content>.
He was hospitalized twice last year, and already twice this year. He has not been able to be weaned off steroids for the past several months.
</text>
</section>
</component>
</StructuredBody>
</component>
</ClinicalDocument>
I used svcutil articles and used following command – but it gave a warning saying that no code is generated.
svcutil.exe /target:code /dataContractOnly /serializer:XmlSerializer /importXmlTypes /collectionType:System.Collections.Generic.List`1 hl7sample.xml
What can done to generate C# Classes from this XML using svcutil?
I have an XML file which has been exported from Orchard CMS, what I need to now do is convert the nodes within the XML file to a new structure so that I can import the file in to Umbraco.
How do I go about doing this? I'm thinking I could write some c# .net to read the XML file and then make the changes I need and then same it as a new file.
Example of a what I am trying to do is:
Exported file:
<BlogPost Id="/alias=The Blog\/2012\/09\/10\/on-starters-orders" Status="Published">
<TextField.Excerpt />
<TaxonomyField.Categories Terms="" />
<TaxonomyField.Tags Terms="" />
<BodyPart Text="MAIN CONTENT OF THE BLOG POST"
/>
<CommonPart Owner="/User.UserName=Owain" Container="/alias=blog" CreatedUtc="2012-09-10T13:27:00Z" PublishedUtc="2012-09-25T08:57:25Z" ModifiedUtc="2012-09-25T08:56:15Z" />
<AutoroutePart Alias="The Blog/2012/09/10/on-starters-orders" UseCustomPattern="false" />
<TitlePart Title="On starters orders....." />
<CommentsPart CommentsShown="true" CommentsActive="true" ThreadedComments="false" />
<TagsPart Tags="" />
</BlogPost>
What I need to convert it to is:
<posts>
<post id="1" date-created="2012-09-25T08:57:25Z" date-modified="2012-09-25T08:56:15Z" approved="true" post-url="on-starters-orders" type="normal" hasexcerpt="false" views="0" is-published="True">
<title type="text"><![CDATA[On starters orders.....]]></title>
<content type="text"><![CDATA[MAIN CONTENT OF THE BLOG POST]]>
</content>
<post-name type="text"><![CDATA[On starters orders.....]]></post-name>
<categories>
<category ref="1018" />
</categories>
<tags>
<tag ref="training" />
</tags>
<comments>
<comment id="35" date-created="2006-09-05T11:36:50" date-modified="2006-09-05T11:36:50" approved="false" user-name="Phil Haack" user-url="http://haacked.com">
<title type="text"><![CDATA[re: CS Dev Guide: Send Emails]]></title>
<content type="text"><![CDATA[Another test comment.]]></content>
</comment>
</comments>
<authors>
<author ref="Owain" />
</authors>
</post>
Looking for suggestion on the best way to do this as I have 150+ posts to convert and don't fancy doing it manually.
You can use XSLT transformation which has a lot of options to do what you are looking for. XSLT can output in xml.
I have some xml like this.
<RootTop>
<FileTablets>
<Tablet Name="">
</Tablet>
</FileTablets>
<DirectoryTablets>
<Directory FullPath="Path1" Id="" />
<Directory FullPath="Path2" Id="" />
<SubPath Path="Path Id="" />
<SubPath Path="Path Id="" />
<SubPath Path="Path Id="" />
</Directory>
</DirectoryTablets>
</RootTop>
When I user dataset.readxml() with inferring schema or read schema, data gets read into the data set but not in the format I want. I want only the information under DirectoryTablets Sub tree. How can I read the data directly into dataset in the format I want
Here is the format I want:
Table name: DirectoryTablets
FullPath Id SubPath-Path SubPath-Id (Empty if subpath nodes don’t exist)
FullPath Id SubPath-Path SubPath-Id
The DataSet class is an in-memory representation of a relational data model.
Not all XML maps to a relational data model.
This means that some XML can't be read into a DataSet.
This includes the XML you posted.
Choose a different mechanism for processing the XML.
I want to manipulate XML files.
...
<Document Id="1091">
<Indexes>
<Index Name="MODD" Value="aaa" />
<Index Name="DDAT" Value="bbb" />
<Index Name="CDAT" Value="ccc" />
<Index Name="MDAT" Value="ddd" />
<Index Name="DOCN" Value="eee" />
<Index Name="STAT" Value="fff" />
...
</Indexes>
</Document>
<Document Id="2088">
...
I have retrieve the value of some index randomly. I would avoid the loop on all the indexes. What is the tool you advise me to use and why?
load the file as a text file and use RegEx
load the xml file and use XPath
load the xml file and use Linq to Xml
generate the classes with xsd.exe or xsd2code
another approach
I'd go with LinqToXml. Good syntax and easy to use!