AnsweredAssumed Answered

ExportXml with XmlWriter bug

Question asked by arosenthal on Feb 3, 2016
Latest reply on Feb 5, 2016 by bshang

I am trying to export library elements using the AFSDK ExportXml function and noticed a bug affecting AFTable elements. It seems that the contents of <Schema> and <DataTable> blocks are not being exported correctly as XML. Instead, they use the &lt; or &gt; escape characters. This does not seem to happen when I call the ExportXml overload to write to a file directly.

 

XDocument libTmp = new XDocument();
using (XmlWriter writer = libTmp.CreateWriter())
{
     PISYS.ExportXml(
          AFDB,
          PIExportMode.AllReferences | PIExportMode.NoUniqueID | PIExportMode.Library | PIExportMode.Flat | PIExportMode.SimplifiedConfigStrings,
          writer, null, null, null);
}

libTmp.Save("test/libTmp.xml");

 

I am saving the XML at the end so that I can view the contents of the XML file. Ideally I would like to just continue processing the XDocument object in memory without having to save it to a file.

 

The problem is that when I export this way, my Schema and DataTable elements for AFTables is not correct. For example, this is what one of my <Schema> blocks looks like with the above export method:

 

      <Schema>
&lt;xs:schema id="AFConfigDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"&gt;
  &lt;xs:element name="AFConfigDataSet" msdata:IsDataSet="true" msdata:Locale=""&gt;
    &lt;xs:complexType&gt;
      &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
        &lt;xs:element name="AFConfig"&gt;
          &lt;xs:complexType&gt;
            &lt;xs:sequence&gt;
              &lt;xs:element name="System" type="xs:string" minOccurs="0" /&gt;
              &lt;xs:element name="Database" type="xs:string" minOccurs="0" /&gt;
              &lt;xs:element name="Attribute" type="xs:string" minOccurs="0" /&gt;
              &lt;xs:element name="Value" type="xs:string" minOccurs="0" /&gt;
            &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
        &lt;/xs:element&gt;
      &lt;/xs:choice&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
&lt;/xs:schema&gt;</Schema>

 

and this is what the <Schema> block looks like when I use ExportXml to write directly to a file instead of piping it through an XmlWriter:

 

      <Schema>
<xs:schema id="AFConfigDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="AFConfigDataSet" msdata:IsDataSet="true" msdata:Locale="">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="AFConfig">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="System" type="xs:string" minOccurs="0" />
              <xs:element name="Database" type="xs:string" minOccurs="0" />
              <xs:element name="Attribute" type="xs:string" minOccurs="0" />
              <xs:element name="Value" type="xs:string" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema></Schema>

 

Is there something I am doing wrong or is this a bug?

Outcomes