oozcitak / xmlbuilder-js

An XML builder for node.js
MIT License
918 stars 107 forks source link

Problem adding child list at 3 level #242

Closed Mateus-pilo closed 3 years ago

Mateus-pilo commented 3 years ago

My XML to be generated is this:

<listing>
    <vehicle_id><![CDATA[1]]></vehicle_id>
    <title><![CDATA[Title]]></title>
    <description><![CDATA[description]]></description>
    <url><![CDATA[<![]]></url>
    <make><![CDATA[description]]></make>
    <image/>
    <url><![CDATA[description]]></url>
    <url><![CDATA[description]]></url>
    <url><![CDATA[description]]></url>
    <url><![CDATA[description]]></url>
    <url><![CDATA[description]]></url>
    <url><![CDATA[description]]></url>
    <url><![CDATA[description]]></url>
    <model><![CDATA[description]]></model>
    <year><![CDATA[<![description]]></year>
    <mileage>
      <value><![CDATA[description]]></value>
      <unit><![CDATA[KM]]></unit>
    </mileage>
    <fuel_type><![CDATA[description]]></fuel_type>
    <transmission><![CDATA[description]]></transmission>
    <dealer_name><![CDATA[description]]></dealer_name>
    <address>
      <component name="city"><![CDATA[description]]></component>
      <component name="region"><![CDATA[description]]></component>
      <component name="postal_code"><![CDATA[description]]></component>
    </address>
    <exterior_color><![CDATA[description]]></exterior_color>
    <sale_price><![CDATA[description]]></sale_price>
    <state_of_vehicle><![CDATA[description]]></state_of_vehicle>
  </listing>

in tag image i have to put the kids but dont work, i try this:

  let images: XMLElement;
      announcement.images.forEach((image) => {
        images = create('url');
        images.cdata(`${image}`);
        listing.importDocument(images);
      });

The other situation when i try generation files of 30 items listing, the last item dont' close the last tags, take this:

 <exterior_color><![CDATA[Rosa]]></exterior_color>
 <sale_price><![CDATA[427303.8]]></sale_price>
 <state_of_vehicle><![CDATA[usado]]></state_of_vehicle

note that the </ state_of_vehicle tag is incomplete and does not close the file nor the<listing>tag i tray this:

content.doc().end({ pretty: true });

oozcitak commented 3 years ago

Did you check the documentation? https://github.com/oozcitak/xmlbuilder-js/wiki#importing-documents

In any case I need to see more of your code.