0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RailsのXML Builder(Builder::XmlMarkup)で名前空間と属性を利用

Last updated at Posted at 2020-02-02

Rails 4でソフトウェアテストのスタブを作成しているが、以下のようなXML表現をBuilder::XMLMarkupでするのに手間取ったのでメモ。

<ns:ParameterList>
  <ns:StringParameter name="txnId">txnId(変数)</ns:StringParameter>
  <ns:ShortParameter name="txnStatus">txnStatus(変数)</ns:ShortParameter>
</ns:ParameterList>

書き方としては、以下のようにnamespaceのprefixコンテンツ属性の順番が書けばよい。属性は複数書いても有効だった。

xml.ns :ParameterList do
  xml.ns :StringParameter, @txnId, :name=>"txnId"
  xml.ns :ShortParameter,  @txnStatus, :name=>"txnStatus" 
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?