【问题标题】:Using GDataXML to get a CGPoint from an xml?使用 GDataXML 从 xml 中获取 CGPoint?
【发布时间】:2011-03-22 22:20:31
【问题描述】:

我目前有一个带有以下代码的 xml:

<Level>
    <!--Loads the animals for the Level-->
    <Animal>
        <Texture>panda.png</Texture>
        <PositionX>100</PositionX>
        <PositionY>50</PositionY>
        <Type>Panda</Type>
    </Animal>
    <Animal>
        <Texture>tiger.png</Texture>
        <PositionX>200</PositionX>
        <PositionY>150</PositionY>
        <Type>Tiger</Type>
    </Animal>
    <Animal>
        <Texture>monkey.png</Texture>
        <PositionX>300</PositionX>
        <PositionY>250</PositionY>
        <Type>Monkey</Type>
    </Animal>
</Level>

我想要的是摆脱 positionX 和 positionY 并将其替换为 CGPoint 变量。 这将使我稍后将在包含多个位置的行中添加的其他项目更容易。

我在互联网上搜索过,但找不到任何 GDataXML 文档。

为了获取我的字符串和整数,我在 GDataXMLElement 上使用了 .stringValue 和 .intValue。

我的问题是,GDataXML 是否有可能从 xml 文件中获取 CGPoint 值,或者我是否必须像我目前拥有的那样将其作为单独的整数?

【问题讨论】:

    标签: iphone objective-c xml gdata cgpoint


    【解决方案1】:

    你错过了How to Read and Write XML Data with GDataXML吗?

    至于 CGPoint,我想你可以随心所欲地对其进行编码。然而,由于一个点由两个单独的值组成,因此将它们分别编码是有意义的,可能在另一个标签内,如下所示:

    <Point x:30 y:100 />
    

    【讨论】:

    • 是的,这就是我最初遵循的教程。好的,如果我像这样将点插入 xml,然后将其作为 GDataXMLElement 读入,那么我将如何将其转换为 CGPoint?
    猜你喜欢
    • 2012-02-03
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    相关资源
    最近更新 更多