Removing textflags in xml2struct?

2 ビュー (過去 30 日間)
Jin Wook Hwang
Jin Wook Hwang 2018 年 2 月 28 日
コメント済み: Jin Wook Hwang 2018 年 3 月 12 日
Hello, I am currently using xml2struct provided in the link below.
I was wondering if there is a way to modify the code so I don't get textflags <Text></Text>.
So input xmlfile of this
<XMLname attrib1="Some value">
<Element>Some text</Element>
</XMLname>
will produce s.XMLname.Element = "Some text";
instead of s.XMLname.Element.Text = "Some text";
Thank you.

採用された回答

Guillaume
Guillaume 2018 年 3 月 9 日
While you could indeed edit the code yourself so it does whatever you want, this whole thing is a very bad idea.
What if the xml is instead:
<XMLname attrib1="Some value">
<Element attrib2="Some other value">Some text</Element>
</XMLname>
Where does attrib2 go in the structure? You do need
s.XMLName.Element.Text = 'Some text';
s.XMLName.Element.Attributes.attrib2 = 'Some other value';
xml2struct exactly reflects the XML DOM. What you're asking breaks from it. It is correct that the text portion of an element should be identified by its own field.
Also, I don't understand why it would be causing problem for you. Why can't you adjust your code so it conform to the xml DOM?
  1 件のコメント
Jin Wook Hwang
Jin Wook Hwang 2018 年 3 月 12 日
Thank you, after studying xml format I realized later that whole idea is somewhat conflicting. I found another way around as you suggested, to conform to the xml DOM. Thanks

サインインしてコメントする。

その他の回答 (1 件)

Sujit Muduli
Sujit Muduli 2018 年 3 月 9 日
編集済み: Walter Roberson 2018 年 3 月 9 日
Hi Jin,
I didn't get a chance to go into the detailed implementation of this function, but yeah it should be possible to get the desired result. You just need to find out the location in the code where the structure is getting created and change the structure definition according to your need. You may refer this documentation link to find out more on struct in MATLAB.
  1 件のコメント
Jin Wook Hwang
Jin Wook Hwang 2018 年 3 月 12 日
Thank you! Found a way to go around the method to achieve my desired output.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructured Data and XML Documents についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by