i have huge xml structure have attached below,
i adding update details , adding data product tracking module when try change it replacing entire xml new xml sample xml
<query_by_gtin_response:querybygtinresponse xmlns:query_by_gtin_response="urn:gs1:tsd:query_by_gtin_response:xsd:1" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="urn:gs1:tsd:query_by_gtin_response:xsd:1 querybygtinresponse.xsd urn:gs1:tsd:basic_product_information_module:xsd:1 basicproductinformationmodule.xsd urn:gs1:tsd:nutritional_product_information_module:xsd:1 nutritionalproductinformationmodule.xsd"> <productdata> <gtin>00000000000509</gtin> <targetmarket>124</targetmarket> <informationprovidergln>1111111133333</informationprovidergln> <informationprovidername>testsub</informationprovidername> <productdatarecord> <module> <bpi:basicproductinformationmodule xmlns:bpi="urn:gs1:tsd:basic_product_information_module:xsd:1"> <productname languagecode="en">waka waka</productname> <brandnameinformation> <brandname>wowozella</brandname> </brandnameinformation> </bpi:basicproductinformationmodule> </module> <module> <nfii:nonfoodingredientinformationmodule xmlns:nfii="urn:gs1:tsd:nonfood_ingredient_information_module:xsd:1"/> </module> <module> <product_tracking_information_module> <variantid>ec9ef090-57c2-11e6-bc2b-51c4bf71f613</variantid> <status/> <name>admin@gmail.com</name> <createdby>552f5b90b348147e03e49b62</createdby> <createddate>2016-08-01t08:35:38.648z</createddate> <updatedby>552f5b90b348147e03e49b62</updatedby> <updateddate>2016-08-01t08:35:38.648z</updateddate> <applicationid>webapp</applicationid> <history> <createddate>2016-08-01t08:35:38.648z</createddate> <updateddate>2016-08-01t08:35:38.648z</updateddate> <status/> <updatedby>552f5b90b348147e03e49b62</updatedby> <createdby>552f5b90b348147e03e49b62</createdby> <applicationid>webapp</applicationid> <name>admin@gmail.com</name> </history> </product_tracking_information_module> </module> </productdatarecord> </productdata> </query_by_gtin_response:querybygtinresponse>
the sample xml want replace current full data in product_tracking_information_module below
<product_tracking_information_module> <variantid>ec9ef090-57c2-11e6-bc2b-51c4bf71f613</variantid> <status>deleted</status> <name>gs1canada</name> <createdby>552f5b90b348147e03e49b62</createdby> <createddate>2016-08-01t08:35:38.648z</createddate> <updatedby>company id 552f5b62b348147e03e49b61</updatedby> <updateddate>2016-08-01t14:52:23.985z</updateddate> <applicationid>serverlet</applicationid> <history> <createddate>2016-08-01t08:35:38.648z</createddate> <updateddate>2016-08-01t08:35:38.648z</updateddate> <status/> <updatedby>552f5b90b348147e03e49b62</updatedby> <createdby>552f5b90b348147e03e49b62</createdby> <applicationid>webapp</applicationid> <name>admin@gmail.com</name> </history> <history status="deleted"> <applicationid/> <updatedby>company id 552f5b62b348147e03e49b61</updatedby> <updateddate>2016-08-01t14:52:23.985z</updateddate> <name>gs1canada</name> </history> </product_tracking_information_module>
and code that, doc xmldom parsed document var ptimdom = new dom().parsefromstring(ptimxml.tostring()); var nodesptim = xpath.select("//productdata//productdatarecord//module//product_tracking_information_module", doc); doc.replacechild(ptimdom,nodesptim[0]);
but result doc after second xml , full data lost.
what doing wrong?
try nodesptim[0].parentnode.replacechild(ptimdom, nodesptim[0])
, call replacechild method on parentnode of element want replace.
Comments
Post a Comment