Namespace not output when serializing
Question asked by Scott Zrubek - May 28 at 7:14 PM
I'm reading in an XML file and then, at some future time, exporting it out again.  the input looks similar to:
    <xtce:Header validationStatus="Draft" classification="Exploration" date="2020-05-29" version="xxx">
I need to get all of those namespaces on the exported XML file.  Currently, I get the following:

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML Objects - Registered to 'NASA Johnson Space Center ' - -->
<SS xmlns:xsi="http://blah2"; xsi:type="SSType" name="Blah" shortDescription="header">
  <Header version="xxx" date="2020-05-29" classification="Exploration" validationStatus="Draft" xmlns="">;
      <Note>Gateway Data Model Version: 1.00.001 (6-30-2020)</Note>
      <Note>Date: Fri May 1 15:51:45 CDT 2020</Note>
  <TMD xmlns="">;

Two questions:

How do I get the xtce prefix onto the elements (and the xmlns:xtce attribute) published?  In order for other tools in our system to handle the file, the prefix must exist.
How do I get newlines put between attributes?


1 Reply

Reply to Thread
Liquid Support Replied
Employee Post Marked As Answer

You can control the output namespaces using the LxWriterSettings.NamespaceMap setting.
Note, if you want to set the default namespace its alias is "".

If you read the XML document in via LxSerializer then setting the LxReaderSettings.IgnoreXmlnsAttributes property to true may also help as it will prevent namespace aliases being stored when the document is being read, meaning you have direct control over the ones added to the header using the code below.

LxWriterSettings settings = new LxWriterSettings();
settings.NamespaceMap["xtce"] = "http://blah1";;
settings.NamespaceMap["xxx"] = "http://blahXXX";;
settings.NamespaceMap.Remove(""); // This removes any declared default namespace (should not exist unless you've explicitly set it)

GenereatedObject myObj = ....

LxSerializer<GenereatedObject> serializer = new LxSerializer<GenereatedObject>();
serializer(@"c:\test.xml", myObj, settings);

If this does not solve the problem, please post the XSD schema (on the forum or via a support ticket) and include a sample XML document.

Reply to Thread