Solved

Xml file Replace values fra XmlValueConvert file

Posted on 2013-11-25
2
377 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
[X]
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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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. 
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

617 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