Help with reorganizing and removing data from data element USING vb.net

Hi,

 I'm exporting data from a PDF file in the following format:

 <?xml version="1.0" encoding="UTF-8"?>
 -<fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">
 -<ListBox1 xfdf:original="ListBox1">
 <value>A-ItemA</Value>
 <value>B-ItemB</value>
 <value>C-ItemC</value>
 <value>D-ItemD</value>
 </ListBox1>
 <ItemType>A</ItemType>
 <Text111>data1</Text111>
 <TxtDate>data2</TxtDate>
 <TxtFT>data3</TxtFT>
 <TxtFuze>data4</TxtFuze>
 <TxtMT>data5</TxtMT>
 <TxtManu>data6</TxtManu>
 </fields>

 How do I rearrange the values in listbox1 and display only the First character in the data elements, as shown below?

 <?xml version="1.0" encoding="UTF-8"?>
<fields>
 <Lisbox1>A,B,C,D</Listbox1>
 <ItemType>A</ItemType>
 <Text111>data1</Text111>
 <TxtDate>data2</TxtDate>
 <TxtFT>data3</TxtFT>
 <TxtFuze>data4</TxtFuze>
 <TxtMT>data5</TxtMT>
 <TxtManu>data6</TxtManu>
 </fields>

 Thanks,

 Victor
vcharlesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi Victor;

This is almost like before.

Dim xdoc = XDocument.Load("From Path & Filename")                                                                                           
                                                                                                                                                          
'' Get a reference to the ListBox1 node                                                                                                                   
Dim listBox = xdoc.Root.Element("ListBox1")
'' Remove the Attributes
listBox.RemoveAttributes()                                                                                                               
'' Build the new value for the ListBox1 node                                                                                                              
Dim listBoxValues = listBox.Elements().Select(vals => vals.Value.Substring(0,1)).Aggregate((workingValues, nextValue) => workingValues + "," + nextValue)
'' Remove all ListBox1 children nodes                                                                                                                     
listBox.Elements().Remove()
'' Add the new Value to the ListBox1 node                                                                                                                 
listBox.Value = listBoxValues;                                                                                                                            
                                                                                                                                                          
'' Save the document                                                                                                                                      
xdoc.Save("To Path & Filename")

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vcharlesAuthor Commented:
Hi,

I will try them later and get back to you.

Thanks,

Victor
0
vcharlesAuthor Commented:
Hi,

They both work.

After the conversion, how do I replace

<fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">

with

<fields>

Thanks,

Victor
0
Fernando SotoRetiredCommented:
To remove the attributes from the Root node you should be able to do this.

xdoc.Root.RemoveAttributes()

this should be done after opening the document.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.