Creating an XML Document to return from function

  • Thread starter Thread starter Bryan Dickerson
  • Start date Start date
B

Bryan Dickerson

Ok, I've spent all this time creating a program to read an XML Document via
XPaths and my boss is pretty thrilled, but now I have to return an XML
document, so can someone point me to some sample code that creates an XML
Doc and adds a field/element to it?

Thanx!
 
Bryan:

The following KB article may be a useful reference, depending on your exact
needs.

http://support.microsoft.com/default.aspx?scid=kb;en-us;317665

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Ok, I've spent all this time creating a program to read an XML Document via
XPaths and my boss is pretty thrilled, but now I have to return an XML
document, so can someone point me to some sample code that creates an XML
Doc and adds a field/element to it?

Thanx!
 
I think that's close, but I'm still grappling with trying to understand some
of the details and how to translate them to my situation. All that to say,
I don't get it yet.

If I want to pass back a very simple XML Document that looks like this:

<?xml version="1.0" encoding="UTF-16" ?>
<Results>
<OrderNumber>123456</OrderNumber>
<Error>[Error messages, if any, go here]</Error>
</Results>

.... what would a sample piece of code look like?

Thanx!
 
Bryan:

The following code sample would create a similar document.

Private Sub btnXML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnXML.Click

Dim doc As XmlDocument = New XmlDocument

Dim dec As XmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-16",
String.Empty)


Dim eResults As XmlNode = doc.CreateElement("Results")

doc.InsertBefore(dec, doc.DocumentElement)

doc.AppendChild(eResults)

Dim eOrderNum As XmlNode = doc.CreateElement("OrderNumber")

eOrderNum.InnerText = "123456"

eResults.AppendChild(eOrderNum)

Dim eError As XmlNode = doc.CreateElement("Error")

eError.InnerText = "[Error messages, if any, go here]"

eResults.AppendChild(eError)

doc.Save(("C:\TestXML.xml"))

End Sub


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I think that's close, but I'm still grappling with trying to understand some
of the details and how to translate them to my situation. All that to say,
I don't get it yet.

If I want to pass back a very simple XML Document that looks like this:

<?xml version="1.0" encoding="UTF-16" ?>
<Results>
<OrderNumber>123456</OrderNumber>
<Error>[Error messages, if any, go here]</Error>
</Results>

.... what would a sample piece of code look like?

Thanx!
 
Thanx! That was exactly what I needed!

David Lloyd said:
Bryan:

The following code sample would create a similar document.

Private Sub btnXML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnXML.Click

Dim doc As XmlDocument = New XmlDocument

Dim dec As XmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-16",
String.Empty)


Dim eResults As XmlNode = doc.CreateElement("Results")

doc.InsertBefore(dec, doc.DocumentElement)

doc.AppendChild(eResults)

Dim eOrderNum As XmlNode = doc.CreateElement("OrderNumber")

eOrderNum.InnerText = "123456"

eResults.AppendChild(eOrderNum)

Dim eError As XmlNode = doc.CreateElement("Error")

eError.InnerText = "[Error messages, if any, go here]"

eResults.AppendChild(eError)

doc.Save(("C:\TestXML.xml"))

End Sub


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or
warranties.


I think that's close, but I'm still grappling with trying to understand
some
of the details and how to translate them to my situation. All that to
say,
I don't get it yet.

If I want to pass back a very simple XML Document that looks like this:

<?xml version="1.0" encoding="UTF-16" ?>
<Results>
<OrderNumber>123456</OrderNumber>
<Error>[Error messages, if any, go here]</Error>
</Results>

... what would a sample piece of code look like?

Thanx!


David Lloyd said:
Bryan:

The following KB article may be a useful reference, depending on your
exact
needs.

http://support.microsoft.com/default.aspx?scid=kb;en-us;317665

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or
warranties.


Ok, I've spent all this time creating a program to read an XML Document
via
XPaths and my boss is pretty thrilled, but now I have to return an XML
document, so can someone point me to some sample code that creates an XML
Doc and adds a field/element to it?

Thanx!
 
Back
Top