Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have an XAML doc that has several textboxes for customer name and contact data (i.e. address, phone, fax, contact name, email address). I have a sub that checks the bound xml document to see if the customer name already exists and if not it creates a new entry for all the text boxes. At least that's the idea. I know there has got to be a way to append all the XMLElements to the source in one fell swoop, but I can't seem to figure out how to streamline this event. I want to include all indenting and XML validation as well.

XML data is formated as such...
XML
<?xml version="1.0" encoding="utf-8"?>
<CustDB xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Customer>
    <Name></Name>
    <Address1></Address1>
    <Address2></Address2>
    <Phone></Phone>
    <Fax></Fax>
    <Cell></Cell>
    <Other></Other>
    <Attn></Attn>
    <Email></Email>
    <SalesPerson></SalesPerson>
  </Customer>
</CustDB>
Posted
Updated 17-Nov-14 8:02am
v2
Comments
Sergey Alexandrovich Kryukov 17-Nov-14 13:55pm    
Are you going to update XAML? But why?
—SA
Sean Donnahoe 17-Nov-14 14:00pm    
All of the textboxes in the XAML are bound and synched to data in the XML file, so they update already when the user form is initialized. The customer name field is a combobox that is populated with the bound "name" data. My XML structure is as below...

<custdb xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<customer>
<name>
<address1>
<address2>
<Phone></Phone>
<fax>
<cell>
<other>
<attn>
<email>
<salesperson>

Sergey Alexandrovich Kryukov 17-Nov-14 14:08pm    
Probably you don't know what XAML does, if used for a Window, Page or UserControl design. It is used during built (build, not runtime) for generation of the code you can find under the "obj" sub-directory. Modification of XAML is useless. You need to add element in the logical tree of the Window (or something).
—SA
Sean Donnahoe 17-Nov-14 14:33pm    
I know exactly what XAML does. I'm not trying to manipulate the XAML, I simply stated that I had an XAML form that had textboxes that were bound to XML data. I need help figuring out how to streamline the AppendChild in the code behind so that my XML doc is formated with the new entry.
Sergey Alexandrovich Kryukov 17-Nov-14 16:00pm    
Very good. Probably I misunderstood you, sorry. Then what's the problem? There are three XML parsers/writers in .NET FCL, you can use any of them...
—SA

1 solution

hello,

Linq to XML.
http://msdn.microsoft.com/en-us/library/bb387061(v=vs.120).aspx[^]

The VB.Net code is:

XML
Dim custDB = _
    <CustDB>
    </CustDB>

Dim customer = _
  <Customer>
    <Name>Mr test</Name>
    <Address1>Add 1</Address1>
    <Address2>add 2</Address2>
    <Phone></Phone>
    <Fax></Fax>
    <Cell></Cell>
    <Other></Other>
    <Attn></Attn>
    <Email></Email>
    <SalesPerson></SalesPerson>
</Customer>

custDB.Add(customer)


it's that simple.

Valery.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900