Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for havig attributes in XML formatter? #61

Open
mfathi91 opened this issue Dec 26, 2023 · 0 comments
Open

Support for havig attributes in XML formatter? #61

mfathi91 opened this issue Dec 26, 2023 · 0 comments

Comments

@mfathi91
Copy link

Hello,
Thank you for the great work. I would like to know if there is (or will be) any support for having attributes in XML elements, instead of having separate XML entities for each message field.


Example:
I have the following .proto file:

syntax = "proto2";

package tutorial;

option java_multiple_files = true;
option java_package = "com.example.tutorial.protos";
option java_outer_classname = "AddressBookProtos";

message Person {
  required string name = 1;
  required int32 id = 2;
  required string email = 3;

  enum PhoneType {
    PHONE_TYPE_UNSPECIFIED = 0;
    PHONE_TYPE_MOBILE = 1;
    PHONE_TYPE_HOME = 2;
    PHONE_TYPE_WORK = 3;
  }

  message PhoneNumber {
    optional string number = 1;
    optional PhoneType type = 2 [default = PHONE_TYPE_HOME];
  }

  repeated PhoneNumber phones = 4;
}

message AddressBook {
  repeated Person people = 1;
}

When I use new XmlFormat().printToString(addressBook), the output string looks like this:

<AddressBook>
  <people>
    <name>John Doe</name>
    <id>1234</id>
    <email>jdoe@example.com</email>
    <phones>
      <number>555-4321-9999</number>
      <type>PHONE_TYPE_HOME</type>
    </phones>
  </people>
</AddressBook>

However, I would like to have the possibility to have some of the fields as attributes:

<AddressBook>
  <people name="John Doe" id="1234" email="jdoe@example.com">
    <phones>
      <number>555-4321-9999</number>
      <type>PHONE_TYPE_HOME</type>
    </phones>
  </people>
</AddressBook>

The second one is arguably more readable and more concise. So, is there (or will there be) any support for it in this library? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant