0

我正在用这段代码生成一个xml,它给了我这样的东西:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<node>
<description>
    <type>5</type>
    <datum>11.11.2021</datum>
    <text>test</text>
</description>

<objlist_test>
    <obj_test action="insertupdate">
        <testfields>1</testfields>
      <testfields>12</testfields>
      <testfields>13</testfields>
    </obj_test>
    <obj_test action="insertupdate">
      <testfields>1</testfields>
      <testfields>12</testfields>
      <testfields>13</testfields>
    </obj_test>
</objlist_test>
const rootNode = xmlbuilder.create("node", {
  standalone: true,
  encoding: "ISO-8859-1",
});

// Description
const descriptionNode = xmlbuilder.create({
  description: {
    type: 5,
    datum: dateStr,
    text: "text",
  },
});
rootNode.importDocument(descriptionNode);

// elementlist
const elementList = xmlbuilder.create("objlist_test");

for (let i: number = 0; i < Object.keys(array).length; i++) {
  const elementNode = xmlbuilder
    .create({ obj_test: array[i] })
    .att("action", "insertupdate");
  elementList.importDocument(elementNode);
}

rootNode.importDocument(elementList);

const res = rootNode.end({ pretty: true });

return res;

我想要做的是得到两个单独的 xml,如下所示:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<node>
<description>
    <type>5</type>
    <datum>11.11.2021</datum>
    <text>test</text>
</description>

<objlist_test>
    <obj_test action="insertupdate">
        <testfields>1</testfields>
      <testfields>12</testfields>
      <testfields>13</testfields>
     
</objlist_test>

因此,如果数组中有两个或多个对象包含数据,则将为这些对象分别生成 xml 文档……</p>

有可能吗?谢谢

4

0 回答 0