Skip to content

关于XML标签中的键值该如何解析? #635

Answered by qicosmos
lamliukang asked this question in Q&A
Discussion options

You must be logged in to vote
  1. 通过attr() 拿到属性值:
struct book_t {
  std::string title;
  std::string author;
};
REFLECTION(book_t, title, author);
struct library {
  iguana::xml_attr_t<book_t> book;
};
REFLECTION(library, book);

void lib_example() {
  std::string str = R"(
  <library name="UESTC library">
    <book id="1234" language="en" edition="1">
      <title>Harry Potter and the Philosopher's Stone</title>
      <author>J.K. Rowling</author>
      </book>
  </library>
)";
  {
    iguana::xml_attr_t<library> lib;
    iguana::from_xml(lib, str);

    auto attr = lib.attr();
    for (auto [k, v] : attr) {
      std::cout << k << ": " << v << "\n";
    }
  }

将会打印出属性名字和值:name: UESTC library

  1. 通过attr()去修改或者增加属性
  {
   …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by poor-circle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #633 on March 18, 2024 07:37.