Solved

Xml file Replace values fra XmlValueConvert file

Posted on 2013-11-25
2
366 Views
Last Modified: 2013-11-29
Hi

I have 2 XML files.

One file with convert2 values :
	<convertvalues>
		<OIOUBLvalue>43</OIOUBLvalue>
		<ConvertFromValue>big bag</ConvertFromValue>
	</convertvalues>

Open in new window


And one where the values in specified tags must be converted :
Value that must be replaced :
 - Invoice\cac:InvoiceLine\cbc:InvoicedQuantity unitCode="time"
>> File Attached : ReplaceFile.xml<<

Example : "time" must be converted to "HUR"


Can you help with som code - THANKS
ReplaceFile.xml
CONVERT-VALUES.xml
0
Comment
Question by:conceptdata
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 39685092
This should get you started, you'll just need to extend it to map any other values you need to  replace:
            XmlDocument source = new XmlDocument();
            XmlDocument convert = new XmlDocument();

            // load source document
            source.Load(@"C:\Temp\ReplaceFile.xml");

            // configure namespaces
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(source.NameTable);
            nsMgr.AddNamespace("x", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
            nsMgr.AddNamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
            nsMgr.AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");

            // load conversion document
            convert.Load(@"C:\Temp\Convert-Values.xml");

            XmlNode toUpdate = source.SelectSingleNode("x:Invoice/cac:InvoiceLine/cbc:InvoicedQuantity[@unitCode='time']", nsMgr);
            if (toUpdate != null)
            {
                XmlNode node = convert.SelectSingleNode("data-set/convertvalues[ConvertFromValue='time']/OIOUBLvalue");
                if (node != null)
                {
                    // update value
                    toUpdate.Attributes["unitCode"].Value = node.InnerText;
                }
            }

            source.Save(@"C:\Temp\ReplaceFile.xml");

Open in new window

0
 

Author Comment

by:conceptdata
ID: 39685188
Hi

And Thanks..

I have found a solution last night, something similar...

So you get the points.. :)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now