【问题标题】:Where are Visio Master Shape properties stored?Visio 主形状属性存储在哪里?
【发布时间】:2018-12-19 17:44:04
【问题描述】:

我有一个解析 Visio 文件的 XML 数据的程序。在这个文件中有一个由几个主形状组成的分组形状。像这样:
每个形状都有一个称为 Pin 的属性


引脚 1 是保存在主形状中的默认值。当我解压 Visio 文件并查看 XML 数据时,“Pin”属性不会显示在 pin 1 上,但它会出现在所有其他 pin 上。

<PageContents xmlns="http://schemas.microsoft.com/office/visio/2012/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xml:space="preserve">
    <Shapes>
        <Shape ID="2010" Type="Group" LineStyle="7" FillStyle="7" TextStyle="7" UniqueID="{B849B0B2-94FC-4CC7-843F-6A55BDBD37E6}">
            <Cell N="PinX" V="8.484814432615094"/>
            <...etc>
            <Section N="Property">
                <Row N="REF">
                    <Cell N="Value" V="X999" U="STR"/>
                    <...etc>
                </Row>
            </Section>
            <Shapes>
                <Shape ID="2" NameU="Pin.1994" IsCustomNameU="1" Name="Pin.1994" IsCustomName="1" Type="Group" Master="126" UniqueID="{216A72DB-F8E9-4C30-9C34-DE9A8448552B}">
                    <Cell N="PinX" V="0.07874015748031506" F="Sheet.1!Width*0.5"/>
                    <...etc>
                    <Shapes>
                        <Text callout and background shapes>
                    </Shapes>
                </Shape>
                <Shape ID="6" NameU="Pin.2002" IsCustomNameU="1" Name="Pin.2002" IsCustomName="1" Type="Group" Master="126">
                    <Cell N="PinX" V="0.07874015748031506" F="Sheet.1!Width*0.5"/>
                    <...etc>
                    <Section N="Property">
                        <Row N="Pin">
                            <Cell N="Value" V="2" U="STR"/>
                        </Row>
                    </Section>
                    <Shapes>
                        <Text callout and background shapes>
                    </Shapes>
                </Shape>
            </Shapes>
        </Shape>
    </Shapes>
</PageContents>

如果我将“Pin”属性重命名为“1”以外的任何内容,该属性将像在 Pin 2 上一样显示。我认为这是因为它存储在 Master Shape 中,但没有“Property” " 标记在主文件中。

<MasterContents xmlns="http://schemas.microsoft.com/office/visio/2012/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xml:space="preserve">
    <Shapes>
        <Shape ID="5" Type="Group" LineStyle="0" FillStyle="0" TextStyle="0" UniqueID="{F811FFC2-FDBC-4EFF-97CF-13F5FFBC677C}">
            <Cell N="PinX" V="0"/>
            <...etc>
        <Section N="User">...</Section>
        <Section N="Geometry">...</Section>
        <Shapes>
            <Shape ID="6" NameU="Text callout" IsCustomNameU="1" Name="Text callout" IsCustomName="1" Type="Group" LineStyle="3" FillStyle="3" TextStyle="3" UniqueID="{4CF654FB-78A6-413C-A551-70A86FC63644}">...</Shape>
        </Shapes>
    </Shapes>
</MasterContents>

由于 Visio 正在显示值,它必须从某处获取属性名称和值,但我不知道它在哪里执行此操作。

当我解析文件时,我会查找“Pin”属性并从形状中的其他属性中提取数据,但是当“Pin”属性不存在时,它将跳过每个 Pin 1 中的所有信息文件。

如果有人想看,我会在此处附上完整的 xml 文件。

Property renamed to "1 "

Property missing

Master126

*编辑:Zipfile with all XML files

*编辑2:VSDX file

【问题讨论】:

  • 嗨,我猜你在找错误的主人,但不可能从 sn-ps 清楚地看到文件结构(链接对我不起作用,我是害怕)。您能否发布完整的 vsdx 文件以便我们进行适当的查看?
  • 嗨,我在开头的帖子中放了一个带有 XML 文件的 Dropbox 链接。
  • 我认为这只是 xml 部分。你有一个完整的 .vsdx 文件吗?查看所有活动部件会有所帮助。
  • 我无法显示实际文件,因为它包含专有的电气原理图。但是我已经将给我问题的主形状复制到了一个新文档中,并在其中复制了这个问题。它似乎给出了相同的行为,即主形状的默认值未显示在页面 XML 文件中。我已将其附加到新的编辑中。

标签: c# xml visio


【解决方案1】:

感谢 vsdx,这很有帮助。

正如您突出显示的那样,“Pin1”形状中的引脚形状数据行不会显示在实例形状 xml (PageContents) 中,因为它是从其主对象继承的值。其他两个具有本地值的形状反映在实例 xml 中。

我认为您遇到的问题是您正在查看错误的主数据,因此找不到您想要的数据。

追溯这一点的方法是,如果您查看页面 xml (page1.xml),您会看到 Pin 形状基于主 ID '6':

[注意 - 我在下面的 sn-ps 中删除了很多 xml,以便更清楚地了解文件的结构。]

<PageContents>
    <Shapes>
        <Shape ID='17' Type='Group' LineStyle='7' FillStyle='7' TextStyle='7'>
            <Shapes>
                <Shape ID='5' NameU='Pin' Name='Pin' Type='Group' Master='6'>

现在您可以查看 masters 集合 (masters.xml),并会看到 ID 属性为 6 的 master('Pin' master)的 rel id 为 'rId2':

<Masters>
    <Master ID='2' NameU='Dynamic connector' IsCustomNameU='1' Name='Dynamic connector' IsCustomName='1'>
        <Rel r:id='rId1'/>
    </Master>
    <Master ID='6' NameU='Pin' IsCustomNameU='1' Name='Pin' IsCustomName='1'>
        <Rel r:id='rId2'/>
    </Master>

现在您已经获得了正确的 rel id 并在 master.xml.rels 中查找正确的主声明,您会看到 rel id 'rId2' 指向 master2.xml:

<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId3" Type="http://schemas.microsoft.com/visio/2010/relationships/master" Target="master3.xml"/>
    <Relationship Id="rId2" Type="http://schemas.microsoft.com/visio/2010/relationships/master" Target="master2.xml"/>
    <Relationship Id="rId1" Type="http://schemas.microsoft.com/visio/2010/relationships/master" Target="master1.xml"/>
    <Relationship Id="rId5" Type="http://schemas.microsoft.com/visio/2010/relationships/master" Target="master5.xml"/>
    <Relationship Id="rId4" Type="http://schemas.microsoft.com/visio/2010/relationships/master" Target="master4.xml"/>
</Relationships>

因此,您的最后一站是前往 master2.xml,您应该会发现顶层形状(id 5)有一个名为“Pin”的形状数据行和一个值“1”:

<MasterContents>
    <Shapes>
        <Shape ID='5' NameU='Pin.473' IsCustomNameU='1' Name='Pin.473' IsCustomName='1' Type='Group'>
            <Section N='Property'>
                <Row N='Pin'>
                    <Cell N='Value' V='1' U='STR'/>
                    <Cell N='Prompt' V='' F='No Formula'/>
                    <Cell N='Label' V='Pin'/>
                    <Cell N='Format' V='' F='No Formula'/>
                    <Cell N='SortKey' V='' F='No Formula'/>
                    <Cell N='Type' V='0'/>
                    <Cell N='Invisible' V='0' F='No Formula'/>
                    <Cell N='Verify' V='0' F='No Formula'/>
                    <Cell N='DataLinked' V='0' F='No Formula'/>
                    <Cell N='LangID' V='sv-SE'/>
                    <Cell N='Calendar' V='0' F='No Formula'/>
                </Row>
            </Section>

我猜您将 vsdx 视为 zip 并且您错过了 System.IO.Packaging 命名空间,这将帮助您导航包关系。我会添加这个链接以防万一:

【讨论】:

  • 太棒了,这很有帮助,感谢您提供 Microsoft 参考资料,我也会通读一遍。