Decorators
TypeSpec.Xml
Section titled âTypeSpec.Xmlâ@attribute
Section titled â@attributeâSpecify that the target property should be encoded as an XML attribute instead of node.
@TypeSpec.Xml.attribute
ModelProperty
Parameters
Section titled âParametersâNone
Examples
Section titled âExamplesâDefault
Section titled âDefaultâmodel Blob { id: string;}
<Blob> <id>abcdef</id></Blob>
With @attribute
Section titled âWith @attributeâmodel Blob { @attribute id: string;}
<Blob id="abcdef"></Blob>
Provide the name of the XML element or attribute. This means the same thing as
@encodedName("application/xml", value)
@TypeSpec.Xml.name(name: valueof string)
unknown
Parameters
Section titled âParametersâName | Type | Description |
---|---|---|
name | valueof string | The name of the XML element or attribute |
Examples
Section titled âExamplesâ@name("XmlBook")model Book { @name("XmlId") id: string; @encodedName("application/xml", "XmlName") name: string; content: string;}
<XmlBook> <XmlId>string</XmlId> <XmlName>string</XmlName> <content>string</content></XmlBook>
Specify the XML namespace for this element. It can be used in 2 different ways:
@ns("http://www.example.com/namespace", "ns1")
- specify both namespace and prefix@Xml.ns(Namespaces.ns1)
- pass a member of an enum decorated with@nsDeclaration
@TypeSpec.Xml.ns(ns: string | EnumMember, prefix?: valueof string)
unknown
Parameters
Section titled âParametersâName | Type | Description |
---|---|---|
ns | string | EnumMember | The namespace URI or a member of an enum decorated with @nsDeclaration . |
prefix | valueof string | The namespace prefix. Required if the namespace parameter was passed as a string. |
Examples
Section titled âExamplesâWith strings
Section titled âWith stringsâ@ns("https://example.com/ns1", "ns1")model Foo { @ns("https://example.com/ns1", "ns1") bar: string;
@ns("https://example.com/ns2", "ns2") bar: string;}
With enum
Section titled âWith enumâ@Xml.nsDeclarationsenum Namespaces { ns1: "https://example.com/ns1", ns2: "https://example.com/ns2",}
@Xml.ns(Namespaces.ns1)model Foo { @Xml.ns(Namespaces.ns1) bar: string;
@Xml.ns(Namespaces.ns2) bar: string;}
@nsDeclarations
Section titled â@nsDeclarationsâMark an enum as declaring XML namespaces. See @ns
@TypeSpec.Xml.nsDeclarations
Enum
Parameters
Section titled âParametersâNone
@unwrapped
Section titled â@unwrappedâSpecify that the target property shouldnât create a wrapper node. This can be used to flatten list nodes into the model node or to include raw text in the model node.
It cannot be used with @attribute
.
@TypeSpec.Xml.unwrapped
ModelProperty
Parameters
Section titled âParametersâNone
Examples
Section titled âExamplesâArray property default
Section titled âArray property defaultâmodel Pet { tags: Tag[];}
<XmlPet> <ItemsTags> <XmlTag> <name>string</name> </XmlTag> </ItemsTags></XmlPet>
Array property with @unwrapped
Section titled âArray property with @unwrappedâmodel Pet { @unwrapped tags: Tag[];}
<XmlPet> <XmlTag> <name>string</name> </XmlTag></XmlPet>
String property default
Section titled âString property defaultâmodel BlobName { content: string;}
<BlobName> <content> abcdef </content></BlobName>
Array property with @unwrapped
Section titled âArray property with @unwrappedâmodel BlobName { @unwrapped content: string;}
<BlobName> abcdef</BlobName>