How to make a section optional when matching with additional data in the Word OpenXml Part?

I use the OpenXML SDK to generate 2013 word files. I work on the server (part of the server solution), so automation is not an option.

Basically, I have an xml file that is output from the backend system. Here is a very simplified example:

<my:Data 
    xmlns:my="https://schemas.mycorp.com">
    <my:Customer>
        <my:Details>
            <my:Name>Customer Template</my:Name>
        </my:Details>
        <my:Orders>
            <my:Count>2</my:Count>
            <my:OrderList>
                <my:Order>
                    <my:Id>1</my:Id>
                    <my:Date>19/04/2017 10:16:04</my:Date>
                </my:Order>
                <my:Order>
                    <my:Id>2</my:Id>
                    <my:Date>20/04/2017 10:16:04</my:Date>
                </my:Order>
            </my:OrderList>
        </my:Orders>
    </my:Customer>
</my:Data>

Then I use the Word Xml display panel to map this data to the content:

enter image description here

I simply duplicate the word file and write new Xml data when creating new files.

This works as expected. When I update the xml part, it displays data from my backend.

Thought there is a case that does not work. If the customer does not have an order, the contents of the template are stored in the document . Xml data:

<my:Data 
    xmlns:my="https://schemas.mycorp.com">
    <my:Customer>
        <my:Details>
            <my:Name>Some customer</my:Name>
        </my:Details>
        <my:Orders>
            <my:Count>0</my:Count>
            <my:OrderList>
            </my:OrderList>
        </my:Orders>
    </my:Customer>
</my:Data>

(see the empty list of orders).

Word xml ( no Order node):

display with empty data

, , .

, , (, , ).

?

PS: , xml PowerShell script, : repro.zip

+6
1

, , .

, Word, XML PowerShell script, XML Word. , Microsoft VSTO , .

#, Word XML-. OpenXML Word Open XML. , XML . , . . xml c:\temp, c:\temp.

- XML, :

customer_<name1>.docx

customer_<name2>.docx

customer_<name3>.docx

.

, XML enter image description here

, xml enter image description here

, .

+1

Source: https://habr.com/ru/post/1016633/


All Articles