Store XML data into RavenDB

651 views
Skip to first unread message

Maria

unread,
Feb 22, 2012, 6:22:43 PM2/22/12
to ravendb
Hi,

I'd like to use raven to load a large amount of XML files. What steps
should I follow to store a single xml file into raven?

thanks ahead,

Maria H.

Oren Eini (Ayende Rahien)

unread,
Feb 22, 2012, 11:22:02 PM2/22/12
to rav...@googlegroups.com
Maria,
Convert that XML to json (you can use the JsonConvert.SerializeXmlNode) and then save it to RavenDB.
RavenDB internally support only json, but you shouldn't have a problem converting between json & xml.

Maria

unread,
Feb 23, 2012, 9:39:30 AM2/23/12
to ravendb

Thanks Oren,

I'm doing as you told me. Once I get the JSON string I call the Store
method I got the exception below. Any special consideration on the XML
format?

Object serialized to String. RavenJObject instance expected.

en Raven.Json.Linq.RavenJObject.FromObject(Object o, JsonSerializer
jsonSerializer) en c:\Builds\raven\Raven.Abstractions\Json\Linq
\RavenJObject.cs:línea 132
en
Raven.Client.Document.InMemoryDocumentSessionOperations.GetObjectAsJson(Object
entity) en c:\Builds\raven\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs:línea 954
en
Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertEntityToJson(Object
entity, RavenJObject metadata) en c:\Builds\raven
\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs:línea 913
en
Raven.Client.Document.InMemoryDocumentSessionOperations.EntityChanged(Object
entity, DocumentMetadata documentMetadata) en c:\Builds\raven
\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs:línea 903
en
Raven.Client.Document.InMemoryDocumentSessionOperations.<PrepareForEntitiesPuts>b__18(KeyValuePair`2
pair) en c:\Builds\raven\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs:línea 783
en System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
en
Raven.Client.Document.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData
result) en c:\Builds\raven\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs:línea 783
en
Raven.Client.Document.InMemoryDocumentSessionOperations.PrepareForSaveChanges()
en c:\Builds\raven\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs:línea 776
en Raven.Client.Document.DocumentSession.SaveChanges() en c:\Builds
\raven\Raven.Client.Lightweight\Document\DocumentSession.cs:línea 406
en RavenTest.Program.Main(String[] args) en c:\users\lina\documents
\visual studio 2010\Projects\RavenTest\RavenTest\Program.cs:línea 29
en System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
en
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
en System.Threading.ThreadHelper.ThreadStart_Context(Object state)
en System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx)
en System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
en System.Threading.ThreadHelper.ThreadStart()


Thanks again,

Maria


On Feb 22, 11:22 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:

Itamar Syn-Hershko

unread,
Feb 23, 2012, 12:51:50 PM2/23/12
to rav...@googlegroups.com
Can you show us a failing test?

wagich

unread,
Mar 2, 2012, 11:21:48 AM3/2/12
to ravendb
Maria,

Just keep in mind that JSON.net doesn't properly handle XML mixed
content! You'll get all text bunched together as the first node and
then all the element nodes.
I had to resort to serializing the XML as a string which is everything
but pretty...

Michael
Reply all
Reply to author
Forward
0 new messages