java-将元素添加到现有XML中的列表中

时间:2013-08-14 10:22:28

标签: java xml dom xpath nodelist

我有一个包含“lineItem”元素的“lineItems”列表,我将它放在XML的不同位置。 我的问题如下: 如何在我想要的特定路径中添加“lineItem”元素? e.g。

<GroupA>
    <Name> </Name>
    <LineItems>
        <LineItem>
            <Age></Age>
            <Description> </Description>
            <Address> </Address>
            <Type></Type>
            <Name> </Name>
        </LineItem>
        <LineItem>
            <Age></Age>
            <Description> </Description>
            <Address> </Address>
            <Type></Type>
            <Name> </Name>
        </LineItem>
    </LineItems>
</GroupA>


<GroupB>
    <Section>
        <GroupOfPpls>
            <GroupOfPpl>
                <TypeOfCharges></TypeOfCharges>
                <Name> </Name>
                <LineItems>
                    <LineItem>
                        <Age> </Age>
                        <Description> </Description>
                        <Address> </Address>
                        <Type> </Type>
                        <Name> </Name>
                    </LineItem>   
                </LineItems>
            </GroupOfPpl>   
        </GroupOfPpls>
    </Section>
    </GroupB>

我在我的代码中使用xpath和nodeList。欢呼:)

1 个答案:

答案 0 :(得分:0)

使用DOM并添加节点。您可以使用XPath获取父节点。see here for a code

相关问题