iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 23
1
自我挑戰組

中年失業大叔的耍廢日記系列 第 23

第廿三天:持續移動的週四

啊啊啊啊,剛剛不小心重整網頁,然後忘記先存檔...還好沒打多少,重新再來吧。時時勤存檔,莫史文重來...

今天要轉移陣地,因為想要搭台鐵的普快晃到台東,又不想趕車,所以會在中途停留一宿。但是...某站前便宜旅館規定要六點才能入住,所以不想太早到,就先慢慢移動。

對了,忽然想起附近咖啡店好像今天有買一送一,等一下退房去瞧瞧...而且接駁車站就在對面。嗯,下一班是10:44左右,就一邊等咖啡一邊觀望。嗯?說是10:44,app上看起來還沒發車,等車快到在去坐車吧。

閒著就寫code...

耶,到站時刻又更新,現在...怎麼突然又有車又沒車的...好,11:14,先相信你...結果已經到逢甲...好,出門吧

到車站先去吃個早午餐,然後去看看咖啡店...如往常地沒位子。不過候車的座位還空著不少,這座位還蠻舒服的,就在這裡等到...三點吧,有點久XD

閒著還是寫點code...

OK,簡單的xsd parser初步可行,就是只顯示element以及下一層。接下來把結果額外處理,加上每個element的parent。如果進一步長下去,手動做一兩層是還好,遞迴做就會碰到xsd結構有遞迴的問題。

來去減輕一下腹腔壓力...出來看了一下,咖啡店還是沒位子,繼續在候車的座位坐一下吧...

寫code殺時間...

ok,parent跟children都跑得出來了:

[
  {
    "name": "aasenv",
    "type": "aas:aasenv_t",
    "minOccurs": "",
    "maxOccurs": "",
    "children": [
      {
        "name": "assetAdministrationShells",
        "type": "aas:assetAdministrationShells_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      },
      {
        "name": "assets",
        "type": "aas:assets_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      },
      {
        "name": "submodels",
        "type": "aas:submodels_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      },
      {
        "name": "conceptDescriptions",
        "type": "aas:conceptDescriptions_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      }
    ],
    "parent": []
  },
  {
    "name": "assetAdministrationShells",
    "type": "aas:assetAdministrationShells_t",
    "minOccurs": "0",
    "maxOccurs": "1",
    "children": [
      {
        "name": "assetAdministrationShell",
        "type": "aas:assetAdministrationShell_t",
        "minOccurs": "0",
        "maxOccurs": "unbounded",
        "children": "circular reference"
      }
    ],
    "parent": [
      {
        "name": "aasenv",
        "type": "aas:aasenv_t",
        "minOccurs": "",
        "maxOccurs": ""
      }
    ]
  },
  {
    "name": "assets",
    "type": "aas:assets_t",
    "minOccurs": "0",
    "maxOccurs": "1",
    "children": [
      {
        "name": "asset",
        "type": "aas:asset_t",
        "minOccurs": "0",
        "maxOccurs": "unbounded",
        "children": "circular reference"
      }
    ],
    "parent": [
      {
        "name": "aasenv",
        "type": "aas:aasenv_t",
        "minOccurs": "",
        "maxOccurs": ""
      }
    ]
  },
  {
    "name": "submodels",
    "type": "aas:submodels_t",
    "minOccurs": "0",
    "maxOccurs": "1",
    "children": [
      {
        "name": "submodel",
        "type": "aas:submodel_t",
        "minOccurs": "0",
        "maxOccurs": "unbounded",
        "children": "circular reference"
      }
    ],
    "parent": [
      {
        "name": "aasenv",
        "type": "aas:aasenv_t",
        "minOccurs": "",
        "maxOccurs": ""
      }
    ]
  },
  {
    "name": "conceptDescriptions",
    "type": "aas:conceptDescriptions_t",
    "minOccurs": "0",
    "maxOccurs": "1",
    "children": [
      {
        "name": "conceptDescription",
        "type": "aas:conceptDescription_t",
        "minOccurs": "0",
        "maxOccurs": "unbounded",
        "children": "circular reference"
      }
    ],
    "parent": [
      {
        "name": "aasenv",
        "type": "aas:aasenv_t",
        "minOccurs": "",
        "maxOccurs": ""
      }
    ]
  },
  {
    "name": "assetAdministrationShell",
    "type": "aas:assetAdministrationShell_t",
    "minOccurs": "0",
    "maxOccurs": "unbounded",
    "children": [
      {
        "name": "derivedFrom",
        "type": "aas:reference_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      },
      {
        "name": "assetRef",
        "type": "aas:reference_t",
        "minOccurs": "1",
        "maxOccurs": "1",
        "children": "circular reference"
      },
      {
        "name": "submodelRefs",
        "type": "aas:submodelRefs_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      },
      {
        "name": "views",
        "type": "aas:views_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      },
      {
        "name": "conceptDictionaries",
        "type": "aas:conceptDictionaries_t",
        "minOccurs": "0",
        "maxOccurs": "1",
        "children": "circular reference"
      }
    ],
    "parent": [
      {
        "name": "assetAdministrationShells",
        "type": "aas:assetAdministrationShells_t",
        "minOccurs": "0",
        "maxOccurs": "1"
      }
    ]
  },
  ...
]

不過看起來還有些地方比較奇怪:

[
  ...
  {
    "name": "key",
    "type": "aas:key_t",
    "minOccurs": "",
    "maxOccurs": "",
    "children": [],
    "parent": []
  },
  ...
]

沒有parent也沒有children XD...之後再處理吧。快三點了,準備進站候車,今天就先這樣吧。


上一篇
第廿二天:旅遊中的週三
下一篇
第廿四天:比較有旅遊感的週五
系列文
中年失業大叔的耍廢日記30

1 則留言

0
海綿寶寶
iT邦大神 1 級 ‧ 2020-10-08 15:41:11

簡單的xsd parser初步可行

請教一下
這個 xsd parser 的最後產出是什麼?
是 json 型式的 xsd 嗎?
而這個 json 又要給誰使用呢?

就我對 xsd 的了解
就算改成 json 型式
應該也不會比較容易使用吧
/images/emoticon/emoticon19.gif

fillano iT邦超人 1 級 ‧ 2020-10-08 17:08:08 檢舉

先說環境在node.js...因為需要匯入與匯出用xsd定義的xml文件,用裡面的資訊操作其他API,同時要能異動xml等,最完整的資訊在xsd裡面。(其實沒這樣要求,只是有這個後面比較方便)然後...爬出element以及他的parent及children應該就夠用。另外,最後是在IOT設備上面跑,一狗票跑完我也怕跑不動,所以預防萬一先拆成幾個部分,有一些直接讀處理過的json就好,不用跑DOM,不然很吃記憶體。

fillano iT邦超人 1 級 ‧ 2020-10-08 17:08:55 檢舉

另一個目的...其實只是玩樂XD

了解,好玩最緊要
/images/emoticon/emoticon58.gif

我要留言

立即登入留言