Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Xml file Replace values fra XmlValueConvert file

Posted on 2013-11-25
2
371 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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