# Writing XML Documents

**URL:** <https://www.ruby-forum.com/t/writing-xml-documents/67239>\
**Category:** Rails\
**Created:** [September 1, 2006, 3:39pm UTC](https://www.ruby-forum.com/t/writing-xml-documents/67239 "2006-09-01T15:39:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amri\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@Amri\_H](https://www.ruby-forum.com/u/Amri_H)\
**Post date:** [September 1, 2006, 3:39pm UTC](https://www.ruby-forum.com/t/writing-xml-documents/67239/1 "2006-09-01T15:39:31Z")

</div>

Dear Ruby on Rails Experts,

I’m having difficulties writing XML document. So far i’ve writen it  
using rxml.

Here is my rxml file :

```
 xml.instruct! :xml, :version=>"1.0"
  xml.Order( "xmlns" => 

```

“urn:oasis:names:specification:ubl:schema:xsd:Order-1.0”,“xmlns:cac” )  
do  
xml.tag!(“BuyersID”,123)  
[1] xml.tag!(“cbc:LineExtensionTotalAmount”,438.50)  
xml.tag!(“cbc:IssueDate”,@order\_o.delivery.order\_date)  
xml.tag!(“cac:BuyerParty”) do  
xml.tag!(“cbc:Party”) do  
xml.tag!(“cbc:PartyName”) do  
xml.tag!(“cbc:Name”,@order\_o.buyer.name)  
end  
xml.tag!(“cbc:Address”) do  
xml.tag!(“cbc:StreetName”,@order\_o.buyer.address)  
xml.tag!(“cbc:ContrySubentityCode”,@order\_o.buyer.country)  
end  
xml.tag!(“cbc:Contact”) do  
xml.tag!(“cbc:name”,@order\_o.buyer.name)  
end  
end  
end  
xml.tag!(“cac:SellerParty”) do  
xml.tag!(“cbc:Party”) do  
xml.tag!(“cbc:PartyName”) do  
xml.tag!(“cbc:Name”,@order\_o.seller.name)  
end  
xml.tag!(“cbc:Address”) do  
xml.tag!(“cbc:StreetName”,@order\_o.seller.address)  
xml.tag!(“cbc:ContrySubentityCode”,@order\_o.seller.country)  
end  
end  
end  
xml.tag!(“cac:Delivery”) do  
xml.tag!(“cac:RequestedDeliveryDateTime”,  
@order\_o.delivery.order\_date)  
xml.tag!(“cac:DeliveryAddress”) do  
xml.tag!(“cbc:StreetName”,@order\_o.delivery.address)  
xml.tag!(“cbc:BuildingNumber”,"")  
xml.tag!(“cbc:ContrySubentityCode”,@order\_o.delivery.country)  
end  
end  
xml.tag!(“cac:DeliveryTerms”) do  
xml.tag!(“cac:SpecialTerms”,@order\_o.delivery.terms)  
end  
end  
end

As you can see at [2], i’m trying to write XML line like this :

\<cbc:LineExtensionTotalAmount amountCurrencyCodeListVersionID=“0.3”  
amountCurrencyID=“USD”\> 438.50 \</cbc:LineExtensionTotalAmount\>

But so far i can only write like this :

cbc:LineExtensionTotalAmount438.50\</cbc:LineExtensionTotalAmount\>

Thank You

p.s. Do anyone know an easy example how Ruby on Rails calls  
Java/.NET/PHP webservices (other than Ruby) ?

Thank you again 😃

---

<div class="post-metadata">

**Author:** ![Amri\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@Amri\_H](https://www.ruby-forum.com/u/Amri_H)\
**Post date:** [September 1, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/writing-xml-documents/67239/2 "2006-09-01T18:16:16Z")

</div>

Amri H. wrote:

> As you can see at [2], i’m trying to write XML line like this :
> 
> \<cbc:LineExtensionTotalAmount amountCurrencyCodeListVersionID=“0.3”  
> amountCurrencyID=“USD”\> 438.50 \</cbc:LineExtensionTotalAmount\>
> 
> But so far i can only write like this :
> 
> cbc:LineExtensionTotalAmount438.50\</cbc:LineExtensionTotalAmount\>
> 
> Thank You
> 
> p.s. Do anyone know an easy example how Ruby on Rails calls  
> Java/.NET/PHP webservices (other than Ruby) ?
> 
> Thank you again 😃

Hi,

You can try something like this to create attributes:

xml.div( :class=\> “leadNotification”)

Thanks,

Michael

---

<div class="post-metadata">

**Author:** ![Amri\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@Amri\_H](https://www.ruby-forum.com/u/Amri_H)\
**Post date:** [September 1, 2006, 7:11pm UTC](https://www.ruby-forum.com/t/writing-xml-documents/67239/3 "2006-09-01T19:11:25Z")

</div>

Michael M. wrote:

> Amri H. wrote:
> 
> > As you can see at [2], i’m trying to write XML line like this :
> > 
> > \<cbc:LineExtensionTotalAmount amountCurrencyCodeListVersionID=“0.3”  
> > amountCurrencyID=“USD”\> 438.50 \</cbc:LineExtensionTotalAmount\>
> > 
> > But so far i can only write like this :
> > 
> > cbc:LineExtensionTotalAmount438.50\</cbc:LineExtensionTotalAmount\>
> > 
> > Thank You
> > 
> > p.s. Do anyone know an easy example how Ruby on Rails calls  
> > Java/.NET/PHP webservices (other than Ruby) ?
> > 
> > Thank you again 😃
> 
> Hi,
> 
> You can try something like this to create attributes:
> 
> xml.div( :class=\> “leadNotification”)
> 
> Thanks,
> 
> Michael

Dear Michael,

Thanx a lot … but can i have an example for this one 😃 please ? coz  
i’m still new in XML writing

Again, Thanx

---

<div class="post-metadata">

**Author:** ![Amri\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@Amri\_H](https://www.ruby-forum.com/u/Amri_H)\
**Post date:** [September 1, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/writing-xml-documents/67239/4 "2006-09-01T20:23:58Z")

</div>

> Dear Michael,
> 
> Thanx a lot … but can i have an example for this one 😃 please ? coz  
> i’m still new in XML writing
> 
> Again, Thanx

Hi Amri,

Try adding that sample to your existing sample. You should end up with  
an element called div, with an attribute called class and a value of  
that attribute as LeadNotification. You can put other elements inside  
of it before you close it out using a standard end statement.

Regards,

Michael
