R
Rob W
Greetings,
I want to use XML LINQ to create xml data that can be transformed to html.
Due to the XML LINQ output being an anonymous type I'm founding it very very
difficult to work with.
I thought I could use an xmltextwriter and stringwriter and feed in the
results from the query (see code at bottom of post).
Firstly I've interchanged the stringWriter and xmltextwriter when I am
writing the xml output.
To use writeElementString to write the output from the query would involve
checking each element if it contained a value or writing more manual
elements in (<quote> start/end element), example xml is as follows:-
<quote>
<date>1st January 2011</date>
<author>Pete</author>
<category>Life</category>
<quotetext>Get out of bed to start the day</quotetext>
</quote>
It complains about the xml enddocument tag, can my requirement be done using
a string writer/xmltextwriter?
Any help and guidance would greatly be appreciated.
Dim doc As XDocument
doc = XDocument.Load("C:\temp\xmltest.xml")
Dim query = _
From quoteElement In doc.<quotefile>.<quote> _
Where quoteElement.<author>.Value = "Einstein" _
Select quoteElement
Dim sw = New StringWriter()
Dim settings = New XmlWriterSettings()
settings.Indent = True
Dim w = XmlTextWriter.Create(sw, settings)
w.WriteStartDocument()
For Each result In query
sw.Write(result)
Next
w.WriteEndDocument()
w.Close()
Console.WriteLine(sw.ToString())
Thanks
Rob
I want to use XML LINQ to create xml data that can be transformed to html.
Due to the XML LINQ output being an anonymous type I'm founding it very very
difficult to work with.
I thought I could use an xmltextwriter and stringwriter and feed in the
results from the query (see code at bottom of post).
Firstly I've interchanged the stringWriter and xmltextwriter when I am
writing the xml output.
To use writeElementString to write the output from the query would involve
checking each element if it contained a value or writing more manual
elements in (<quote> start/end element), example xml is as follows:-
<quote>
<date>1st January 2011</date>
<author>Pete</author>
<category>Life</category>
<quotetext>Get out of bed to start the day</quotetext>
</quote>
It complains about the xml enddocument tag, can my requirement be done using
a string writer/xmltextwriter?
Any help and guidance would greatly be appreciated.
Dim doc As XDocument
doc = XDocument.Load("C:\temp\xmltest.xml")
Dim query = _
From quoteElement In doc.<quotefile>.<quote> _
Where quoteElement.<author>.Value = "Einstein" _
Select quoteElement
Dim sw = New StringWriter()
Dim settings = New XmlWriterSettings()
settings.Indent = True
Dim w = XmlTextWriter.Create(sw, settings)
w.WriteStartDocument()
For Each result In query
sw.Write(result)
Next
w.WriteEndDocument()
w.Close()
Console.WriteLine(sw.ToString())
Thanks
Rob