Is there a standard or guide for creating XML files?

I am curious if there is a standard or guideline for determining what types of things should be attributes and elements in an XML file.

I am also wondering how to create xmlarray and xmlarrayitem lists using XMLSerializer. For example, if I have the following:

<SomeBaseTag>
   <Item1 Attr11="one" Attr12="two" />
   <Item1 Attr11="one" Attr12="two" />
   <Item1 Attr11="one" Attr12="two" />
   <Item2 Attr21="one" Attr22="two" />
   <Item2 Attr21="one" Attr22="two" />
   <Item2 Attr21="one" Attr22="two" />
</SomeBaseTag>

Should I change it to:

<SomeBaseTag>
  <Item1s>
     <Item1 Attr11="one" Attr12="two" />
     <Item1 Attr11="one" Attr12="two" />
     <Item1 Attr11="one" Attr12="two" />
  </Item1s>
  <Item2s>
     <Item2 Attr21="one" Attr22="two" />
     <Item2 Attr21="one" Attr22="two" />
     <Item2 Attr21="one" Attr22="two" />
  </Item2s>
</SomeBaseTag>
+3
source share
8 answers

It all depends on the semantics of what you are trying to represent using your XML document.

For example, if your represents a market stall and represents apples, but represents oranges, then the first format is ideal. SomeBaseTag Item1 Item2

, , , . , SomeBaseTag ** Item1 ** s , ** Item2 ** s .

, , , .

+3

, . .

, . , . , "<" . , , .

. XML . , WSDL, , -, messages:

<wsdl>
    <types/>

    <message/>
    <message/>
    <message/>

    <portTypes/>
    <bindings/>
    <service/>
</wsdl>

, <messages/>.

+2

- xmls , . , xmls - , , , element vs. . xml , xml

+1

, " ". XML :

  • , - .
  • , .
  • ​​ .
  • , .
  • , .

, , , , . :

<SomeBaseTag>
    <SomeItemTag>
        <SomeAttributeTag>one</SomeAttributeTag>
        <AnotherAttributeTag>two</AnotherAttributeTag>
    </SomeItemTag>
    <SomeItemTag>
        <SomeAttributeTag>one</SomeAttributeTag>
        <AnotherAttributeTag>two</AnotherAttributeTag>
    </SomeItemTag>
</SomeBaseTag>

"", "" "primeFactor", , "Item" "attribute".

+1

, XML-. , .

1:

<SomeBaseTag>   
    <Item1/>
    <Item1/>
    <Item2/>

2:

<SomeBaseTag>   
    <Set1>
      <Item1/>
      <Item1/>
    </Set1>
    <Set2>
        <Item2/>
    </Set2>

Item1 Item2 , () . - , .

. , . . WSDL .

WSDL:

<wsdl>
    <types/>

    <message/>
    <message/>
    <message/>

    <portTypes/>
    <bindings/>
    <service/>
</wsdl>

, " ".

<wsdl>
    <schema/>        
    <schema/>        
    <schema/>        
    <message/>
    <message/>
    <message/>

    <operation/>
    <operation/>
    <operation/>
    <binding/>
    <binding/>
    <binding/>
    <service/>
</wsdl>

, portType, .

+1

. , , YAML JSON.

EDIT: ,

SomeBaseTag:
    Item1s:
        - {Attr11: one, Attr12: two}
        - {Attr11: one, Attr12: two}
    Item2s:
        - {Attr21: one, Attr22: two}
        - {Attr21: one, Attr22: two}
0

, - , XML. , XML-. XML, . DOCTYPE, , XML, Schema, . , , XML, .

, , . , , , , . - . , 2 4, .

0

" ", . , XML - , , , .

-1

Source: https://habr.com/ru/post/1715656/


All Articles