Solved

Xml file Replace values fra XmlValueConvert file

Posted on 2013-11-25
2
365 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
Comment Utility
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
Comment Utility
Hi

And Thanks..

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

So you get the points.. :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

17 Experts available now in Live!

Get 1:1 Help Now