Hi,
I'm not seeing an issue when I use the Bookstore sample...
using LiquidTechnologies.XmlObjects;
using LiquidXmlObjects.BookStore.Bs;
using System;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string sampleXml = @"<bs:bookstore xmlns:bs='http://www.liquid-technologies.com/sample/bookstore'; >
<bs:book price='23.99' publicationdate='2002-06-01' ISBN='0596002521'>
<bs:title>XML Schema</bs:title>
<bs:author>
<bs:first-name>Eric</bs:first-name>
<bs:last-name>van der Vlist</bs:last-name>
</bs:author>
<bs:genre>Reference</bs:genre>
</bs:book>
</bs:bookstore>";
LxSerializer<BookstoreElm> serializer = new LxSerializer<BookstoreElm>();
BookstoreElm bookstore;
using (StringReader reader = new StringReader(sampleXml))
{
bookstore = serializer.Deserialize(reader);
}
BookTypeCt newBook = new BookTypeCt();
newBook.Price = 7.99;
newBook.Publicationdate = LxDateTime.CreateDate(2001, 12, 07);
newBook.ISBN = "9780130655677";
newBook.Title = "Definitive XML Schema";
newBook.Author.First_Name = "Priscilla";
newBook.Author.Last_Name = "Walmsley";
newBook.Genre = "Reference";
bookstore.Books.Add(newBook);
// Display details about the books
foreach (var book in bookstore.Books)
Console.WriteLine($"Book[{book.Genre}] : '{book.Title}' ('${book.Price}') by '{book.Author.First_Name} {book.Author.Last_Name}' published on '{book.Publicationdate}'");
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, bookstore);
Console.WriteLine(writer.ToString());
}
string sampleJson;
LjSerializer<BookstoreElm> jSerializer = new LjSerializer<BookstoreElm>();
using (StringWriter jWriter = new StringWriter())
{
jSerializer.Serialize(jWriter, bookstore);
sampleJson = jWriter.ToString();
Console.WriteLine(sampleJson);
}
using (StringReader jReader = new StringReader(sampleJson))
{
bookstore = jSerializer.Deserialize(jReader);
}
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, bookstore);
Console.WriteLine(writer.ToString());
}
// Display details about the books
foreach (var book in bookstore.Books)
Console.WriteLine($"Book[{book.Genre}] : '{book.Title}' ('${book.Price}') by '{book.Author.First_Name} {book.Author.Last_Name}' published on '{book.Publicationdate}'");
}
}
}
This code uses the XML Serializer to read XML data into the object model, update the XML data, and write out the XML data.
It then uses the JSON Serializer to write out the XML Data as JSON and read it back into the object model.
As you can see the JSON data includes the namespace data:
"bs:bookstore": {
"@xmlns:bs": "http://www.liquid-technologies.com/sample/bookstore";,
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance";,
"bs:book": [
{
"@ISBN": "0596002521",
"@price": 23.99,
"@publicationdate": "2002-06-01",
"bs:title": "XML Schema",
"bs:author": {
"bs:first-name": "Eric",
"bs:last-name": "van der Vlist"
},
"bs:genre": "Reference"
},
{
"@ISBN": "9780130655677",
"@price": 7.99,
"@publicationdate": "2001-12-07Z",
"bs:title": "Definitive XML Schema",
"bs:author": {
"bs:first-name": "Priscilla",
"bs:last-name": "Walmsley"
},
"bs:genre": "Reference"
}
]
}
}
Can you please provide an example where this is not the case?