Solved

Xml file Replace values fra XmlValueConvert file

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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