How to use AppendChild() in a schema-compliant manner RRS feed

  • Question

  • I was under the impression that the SDK enforces schema compliance (without necessarily ensuring semantic integrity), but I am now in doubt about this.

    When using the AppendChild() method to add a child element to an OpenXmlElement, what is the correct way to ensure that the resultant Xml will be correctly sequenced according to the schema.

    For example, when manipulating a worksheet using the Worksheet class, if a SheetData instance is added after a Hyperlinks instance, it produces Xml that is schema-invalid and rejected by Excel. Is there any way to use this method (or an alternative technique) that ensures that element sequencing will be internally resolved within the SDK?
    Thursday, November 5, 2009 9:14 AM

All replies

  • AppendChild() itself won't check if the produced xml is valid, but SDK provides a function under DocumentFormat.OpenXml.Validation to handle this, you can validate an Element, or a package, or a part.

    Here's code to initiate a validator:
    OpenXmlValidator v = new OpenXmlValidator();

    Wednesday, November 11, 2009 1:55 AM