use section of XML as source/destination of XmlSerializer?

  • Thread starter Thread starter Craig Buchanan
  • Start date Start date
C

Craig Buchanan

I have an Xml file that I use as a database of information about a
manufactures products. It has the format:

<Manufacturer>
<Products>
<Product id="1" name="product a" price="1.00" />
...
</Products>
<Suppliers>
<Supplier id="1" name="supplier x" />
...
</Suppliers>
</Manufacturer>

I would like to be able to use the Suppliers node as the source for the
XmlSerializer's Deserialize and Serialize methods. I figure that I can load
an XmlDocument, then select the Suppliers node using an Xpath query
(//Supplers). The question is how to send this to the XmlSerialier.
Moreover, what approach should it take for the serialization?

Any thoughts would be appreciated.

Thanks,

Craig Buchanan
 
I have an Xml file that I use as a database of information about a
manufactures products.  It has the format:

<Manufacturer>
    <Products>
        <Product id="1" name="product a" price="1.00" />
        ...
    </Products>
    <Suppliers>
        <Supplier id="1" name="supplier x" />
        ...
    </Suppliers>
</Manufacturer>

I would like to be able to use the Suppliers node as the source for the
XmlSerializer's Deserialize and Serialize methods.  I figure that I canload
an XmlDocument, then select the Suppliers node using an Xpath query
(//Supplers).  The question is how to send this to the XmlSerialier.
Moreover, what approach should it take for the serialization?

I'm guessing that getting the path from an XmlDocument object will
work just fine but that is the only thing you are going to be able to
use it for. May as well dispose that object after getting the path
from it. Of course, this only applies to Deserializing the object. You
will not need the XmlDocument to Serialze, as the path will be in the
object already, right?
 
i need to load the Node into a stream which can be fed to the XmlSerializer.
this is the challenge.

I have an Xml file that I use as a database of information about a
manufactures products. It has the format:

<Manufacturer>
<Products>
<Product id="1" name="product a" price="1.00" />
...
</Products>
<Suppliers>
<Supplier id="1" name="supplier x" />
...
</Suppliers>
</Manufacturer>

I would like to be able to use the Suppliers node as the source for the
XmlSerializer's Deserialize and Serialize methods. I figure that I can
load
an XmlDocument, then select the Suppliers node using an Xpath query
(//Supplers). The question is how to send this to the XmlSerialier.
Moreover, what approach should it take for the serialization?

I'm guessing that getting the path from an XmlDocument object will
work just fine but that is the only thing you are going to be able to
use it for. May as well dispose that object after getting the path
from it. Of course, this only applies to Deserializing the object. You
will not need the XmlDocument to Serialze, as the path will be in the
object already, right?
 
I'm guessing that getting the path from an XmlDocument object will
work just fine but that is the only thing you are going to be able to
use it for. May as well dispose that object after getting the path
from it. Of course, this only applies to Deserializing the object. You
will not need the XmlDocument to Serialze, as the path will be in the
object already, right?

Out of curiosity, what unmanaged resource does the XMLDocument contain that
that has to be disposed?

Cor
 
Craig,

I am lazy with XML files. I simple read them all into a dataset and process
the tables.

ds.ReadXml(path)

Cor
 
Craig said:
I have an Xml file that I use as a database of information about a
manufactures products. It has the format:

<Manufacturer>
<Products>
<Product id="1" name="product a" price="1.00" />
...
</Products>
<Suppliers>
<Supplier id="1" name="supplier x" />
...
</Suppliers>
</Manufacturer>

I would like to be able to use the Suppliers node as the source for the
XmlSerializer's Deserialize and Serialize methods. I figure that I can load
an XmlDocument, then select the Suppliers node using an Xpath query
(//Supplers). The question is how to send this to the XmlSerialier.

Use an XmlNodeReader over the Suppliers XmlElement node e.g.
Dim doc As New XmlDocument()
doc.Load("file.xml")
Dim suppliers as XmlNode =
doc.SelectSingleNode("/Manufacturer/Suppliers")
Dim reader As XmlReader = New XmlNodeReader(suppliers)
' now pass reader to Deserialze method of an XmlSerializer
 
Excellent, thanks!

I have another question for you. Actually, more of an approach. My
application is based on a plugin architecture. Each plugin have settings
that don't fit nicely into the My.Settings.* model. Rather, it makes sense
to represent them in XML (essentially serialized classes that are contained
in the plugin). Thus far, I have them stored in an XML document. In your
opinion, is this a good approach? It seems a bit fragile. Can you suggest
another approach?

Thanks,

Craig
 
Back
Top