1
Namespace not output when serializing
Question asked by Scott Zrubek - 5/28/2020 at 7:14 PM
Answered
I'm reading in an XML file and then, at some future time, exporting it out again.  the input looks similar to:
<xtce:SS 
	xmlns:xtce="http://blah1"; 
	xmlns:xsi="http://blah2"; 
	xsi:schemaLocation="http://blah3"; 
	name="Blah" 
	shortDescription="header">
    <xtce:Header validationStatus="Draft" classification="Exploration" date="2020-05-29" version="xxx">
        <xtce:AuthorSet>
            <xtce:Author>GDS</xtce:Author>
        </xtce:AuthorSet>
        <xtce:NoteSet>
        </xtce:NoteSet>
    </xtce:Header>
    <xtce:TMD>
    </xtce:TMD>
</xtce:SS>
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 ' - https://www.liquid-technologies.com/xml-objects -->
<SS xmlns:xsi="http://blah2"; xsi:type="SSType" name="Blah" shortDescription="header">
  <Header version="xxx" date="2020-05-29" classification="Exploration" validationStatus="Draft" xmlns="http://www.omg.org/spec/XTCE/20180204">;
    <AuthorSet>
      <Author>GDS</Author>
    </AuthorSet>
    <NoteSet>
      <Note>UM_ECLSS_App_1</Note>
      <Note>Gateway Data Model Version: 1.00.001 (6-30-2020)</Note>
      <Note>Date: Fri May 1 15:51:45 CDT 2020</Note>
    </NoteSet>
  </Header>
  <TMD xmlns="http://www.omg.org/spec/XTCE/20180204">;
  </TMD>
</SS>

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?

Thanks!

1 Reply

Reply to Thread
0
Liquid Support Replied
Employee Post Marked As Answer
Hi,

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