• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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
0
vcharles
Asked:
vcharles
  • 2
  • 2
1 Solution
 
Fernando SotoCommented:
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
 
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 SotoCommented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now