You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Krishnakanth <kr...@maxxion.com> on 2006/06/09 08:59:52 UTC
XML Help
Hai Friends,
I'm very new in XML and I don't know much more about XML.My target is to compare 2 xml files and insert the new values from second XML to the first one.
ie, I've one xml file that contains <Table> tags and inside that <Fields> under that <Field> tags.So one table tag contails one <Fields> tag and more number of <Fields> tags . <Field> tag is just like this - <Field name = "name of the field" value = "value of the field" >.The first file may contains lot of <Field> tags similarlly second also contains same or different fields under same <Table> tag.Now I want to compare the two files and append the fields to the first file that are not in first file and in the second file.
First XML:
<parameters>
<table name="table 1">
<fields>
<field name="field 1" value = "value1">
<field name="field 2" value = "value2">
<field name="field 3" value = "value3">
</fields>
</table>
<table name="table 2">
<fields>
<field name="field 4" value = "value4">
<field name="field 5" value = "value5">
<field name="field 6" value = "value6">
</fields>
</table>
</parameters>
Second XML:
<parameters>
<table name="table 1">
<fields>
<field name="field 1" value = "value1">
<field name="field 7" value = "value7">
<field name="field 8" value = "value8">
</fields>
</table>
<table name="table 2">
<fields>
<field name="field 9" value = "value9">
<field name="field 5" value = "value5">
<field name="field 10" value = "value10">
</fields>
</table>
</parameters>
So I want to compare these two files and append these
<field name="field 7" value = "value7">
<field name="field 8" value = "value8">
two fields to the table 1 and the following two field tags to table 2
<field name="field 9" value = "value9">
<field name="field 10" value = "value10">
so finally first XML will com like this,
<parameters>
<table name="table 1">
<fields>
<field name="field 1" value = "value1">
<field name="field 2" value = "value2">
<field name="field 3" value = "value3">
<field name="field 7" value = "value7">
<field name="field 8" value = "value8">
</fields>
</table>
<table name="table 2">
<fields>
<field name="field 4" value = "value4">
<field name="field 5" value = "value5">
<field name="field 6" value = "value6">
<field name="field 9" value = "value9">
<field name="field 10" value = "value10">
</fields>
</table>
</parameters>
Note : I just took the getElementByTagName("table") that time I got the length as 2 it is ok.but after that I iterate that NodeList in a for loop and take NodeList.item(i).getChildNodes, Now I get some 8 or 10 childs....So I'm totally confused....
Any Idea Please advise....
Urgent !!! Urgent !!! Urgent !!! Urgent !!! Urgent !!!
Thanks in advance..........
Regards,
Krishna
Re: [OT] Re: XML Help
Posted by Dave Newton <ne...@pingsite.com>.
Krishnakanth wrote:
> I want to compare each of the key values with the previous XML(ie,
> from the DB) and if particular node is already existing in the
> PreviousXML remove that node and create a new node with the new values
> and insert in to the PreviousXML.If the hashtable key values are not
> in the PreviousXML I can directly create the node and append to the
> PreviousXML.
So what's the problem? How you solve this will depend on what XML
library you're using etc. I generally use dom4j and stuff like that is
pretty trivial. (Well, actually, I do almost all XML manipulation w/
Ruby now :)
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: XML Help
Posted by Krishnakanth <kr...@maxxion.com>.
Hai all,
Thanks for your advise.
As per Meena told I also notice that there is some "text nodes"
comes while parsing XML file.The type of that node is "Text" and the
value/name is something like "#text" ....
For Mr.Dave:
Hai Dave thanks for your mail...I think you are also bit confused with
my question.:-)Okey man....once more I'll tell you.I've a xml file in the
database.we can call it as a previous XML.okey....then I have some Input
values,as you to mentioned here like a HashMap / Hashtable.That contains
some fields and the corresponding values.I want to compare each of the key
values with the previous XML(ie, from the DB) and if particular node is
already existing in the PreviousXML remove that node and create a new node
with the new values and insert in to the PreviousXML.If the hashtable key
values are not in the PreviousXML I can directly create the node and append
to the PreviousXML.
This is my target...
Regards,
Krishna....
----- Original Message -----
From: "Meenakshi Rm" <me...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, June 09, 2006 5:46 PM
Subject: Re: [OT] Re: XML Help
>I have had such scenarios, sometimes in your xml if you have tabs or other
> escape characters it adds them on as text nodes while parsing. So you may
> have to modify your xml to be free of such characters.
>
> To find it out print out each node type, you will be able to resolve.
>
> Hope this helps.
>
> Regards,
> Meena.
>
>
>
> On 6/9/06, Dave Newton <ne...@pingsite.com> wrote:
>>
>> Krishnakanth wrote:
>> > Note : I just took the getElementByTagName("table") that time I got the
>> length as 2 it is ok.but after that I iterate that NodeList in a for loop
>> and take NodeList.item(i).getChildNodes, Now I get some 8 or 10
>> childs....So I'm totally confused....
>> >
>> > Any Idea Please advise....
>> >
>>
>> Me too, since you didn't provide any information about how you're
>> accessing the XML, etc.
>>
>> Simplistic XML merging (for me) has generally consisted only of a couple
>> of hash tables and loops and minor decision-making about which
>> attributes to use for node 'equality' comparisons.
>>
>> It sounds like you're having problems at an even higher level, i.e., you
>> don't know how to use your XML library. Can't help, don't know what
>> you're using and how it represents elements.
>>
>> > Urgent !!! Urgent !!! Urgent !!! Urgent !!! Urgent !!!
>> >
>>
>> If it's that urgent you might want to consider Google or an XML forum.
>>
>> Dave
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: XML Help
Posted by Meenakshi Rm <me...@gmail.com>.
I have had such scenarios, sometimes in your xml if you have tabs or other
escape characters it adds them on as text nodes while parsing. So you may
have to modify your xml to be free of such characters.
To find it out print out each node type, you will be able to resolve.
Hope this helps.
Regards,
Meena.
On 6/9/06, Dave Newton <ne...@pingsite.com> wrote:
>
> Krishnakanth wrote:
> > Note : I just took the getElementByTagName("table") that time I got the
> length as 2 it is ok.but after that I iterate that NodeList in a for loop
> and take NodeList.item(i).getChildNodes, Now I get some 8 or 10
> childs....So I'm totally confused....
> >
> > Any Idea Please advise....
> >
>
> Me too, since you didn't provide any information about how you're
> accessing the XML, etc.
>
> Simplistic XML merging (for me) has generally consisted only of a couple
> of hash tables and loops and minor decision-making about which
> attributes to use for node 'equality' comparisons.
>
> It sounds like you're having problems at an even higher level, i.e., you
> don't know how to use your XML library. Can't help, don't know what
> you're using and how it represents elements.
>
> > Urgent !!! Urgent !!! Urgent !!! Urgent !!! Urgent !!!
> >
>
> If it's that urgent you might want to consider Google or an XML forum.
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
[OT] Re: XML Help
Posted by Dave Newton <ne...@pingsite.com>.
Krishnakanth wrote:
> Note : I just took the getElementByTagName("table") that time I got the length as 2 it is ok.but after that I iterate that NodeList in a for loop and take NodeList.item(i).getChildNodes, Now I get some 8 or 10 childs....So I'm totally confused....
>
> Any Idea Please advise....
>
Me too, since you didn't provide any information about how you're
accessing the XML, etc.
Simplistic XML merging (for me) has generally consisted only of a couple
of hash tables and loops and minor decision-making about which
attributes to use for node 'equality' comparisons.
It sounds like you're having problems at an even higher level, i.e., you
don't know how to use your XML library. Can't help, don't know what
you're using and how it represents elements.
> Urgent !!! Urgent !!! Urgent !!! Urgent !!! Urgent !!!
>
If it's that urgent you might want to consider Google or an XML forum.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org