473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlDocument.Sav e() - write raw

Hi;

I have nodes in the XmlDocument I create that need to be written exactly as
is - not converting < to %lt; and no changing the whitespace. (This is for
the SpreadsheetML schema and it reads the <Data> nodes literally.)

How can I do this?

--
thanks - dave
Nov 12 '05 #1
4 2452
Hello!
I have nodes in the XmlDocument I create that need to be written exactly as
is - not converting < to %lt; and no changing the whitespace. (This is for
the SpreadsheetML schema and it reads the <Data> nodes literally.)


AFAIK that's not possible with XmlDocument. But XmlTextWriter has a
WriteRaw-Method.
Is it really not possible to use &lt; or <[CDATA[..]]>?
For <x>5&lt;7</x> a parser will see a text node containing "5<7".
--
Pascal Schmitt
Nov 12 '05 #2
Hi;

The problem inside the <Data> nodes is that:
<Data>before <b>middle</b> end</Data>
is different from:
<Data>before
<b>middle</b>
end</Data>

The first is a single line in an Excel cell while the second is 3
paragraphs. It's very weird. But it's how Excel works so I'm stuck with it.

--
thanks - dave
"Pascal Schmitt" wrote:
Hello!
I have nodes in the XmlDocument I create that need to be written exactly as
is - not converting < to %lt; and no changing the whitespace. (This is for
the SpreadsheetML schema and it reads the <Data> nodes literally.)


AFAIK that's not possible with XmlDocument. But XmlTextWriter has a
WriteRaw-Method.
Is it really not possible to use < or <[CDATA[..]]>?
For <x>5<7</x> a parser will see a text node containing "5<7".
--
Pascal Schmitt

Nov 12 '05 #3
Hello!
The problem inside the <Data> nodes is that:
<Data>before <b>middle</b> end</Data>
is different from:
<Data>before
<b>middle</b>
end</Data>

The first is a single line in an Excel cell while the second is 3
paragraphs. It's very weird. But it's how Excel works so I'm stuck with it.


It should help to disable indentation when saving the XmlDocument. This
will cause the entire document to appear in one line without any extra
spaces or line-breaks.
--
Pascal Schmitt
Nov 12 '05 #4
This doesn't make sense in an XMLDocument, as it's not possible to have a
node value that contains tags (as these would be node type tag), but there
are places where CDATA is not going to work because you want to perform
transformations on the XML file and your code contains tags in strings.

However, it does make sense if you want to generate XML from an object
tree, and have decided to code your own nodes as strings that may contain
mixed XML data.
One example might be to allow a node that may contain a subset of HTML that
you have defined in a schema as a mixed type node.
If you encode this as a string then it will always be escaped by the
XMLSerializer, but you can get around this by implementing interface
Xml.Serializati on.IXmlSerializ able.
If the XML Serializer detects this then it calls your implementation
instead of its own.

Here's an example in VB.Net I use to implement a collection of language
specific elements such as
<LanguageString s>
<LanguageStri ng Language="" TranslationStat us="Changed">
Are you <B>certain</B> that you want to do <U>this</U> with your XML?
</LanguageString>
</LanguageStrings >

As you can see, there are tagged values in the string that we want to
remain as valid XML so we can transform them to other formats at render
time, and we've already validated them and they are correct for the schema.

Here's the code:

Public Function GetSchema() As System.Xml.Sche ma.XmlSchema Implements System.Xml.Seri alization.IXmlS erializable.Get Schema
Return Nothing
End Function

Public Sub ReadXml(ByVal reader As System.Xml.XmlR eader) Implements System.Xml.Seri alization.IXmlS erializable.Rea dXml
reader.ReadStar tElement()
reader.MoveToCo ntent()

reader.ReadStar tElement()
reader.MoveToCo ntent()

Me.arrLanguageS trings.Clear()

Dim lang As String = ""
Dim ts As Object = Nothing

While reader.NodeType <> XmlNodeType.End Element
If reader.HasAttri butes() Then
Try
lang = reader.GetAttri bute("Language" )
ts = reader.GetAttri bute("Translati onStatus")
Catch ex As Exception
Debug.WriteLine ("Error reading attributes:" + ex.ToString)
End Try
Else
lang = ""
End If
Dim Value As String = reader.ReadInne rXml
Me.Item(lang) = Value

If Not ts Is Nothing Then
SetTranslationS tatus(lang, _
CType(System.En um.Parse(GetTyp e(LanguageStrin gObject.enumTra nslationstatus) , ts.ToString), _
LanguageStringO bject.enumTrans lationstatus))
End If

reader.MoveToCo ntent()
End While
'

If Me.arrLanguageS trings.Count > 0 Then
reader.MoveToCo ntent()
reader.ReadEndE lement()
End If

reader.MoveToCo ntent()
reader.ReadEndE lement()
End Sub

Public Sub WriteXml(ByVal writer As System.Xml.XmlW riter) Implements System.Xml.Seri alization.IXmlS erializable.Wri teXml
writer.WriteSta rtElement("Lang uageStrings")

For Each lso As LanguageStringO bject In arrLanguageStri ngs
writer.WriteRaw ("<LanguageStri ng Language=""" + lso.Lang + """ TranslationStat us=""" + lso.translation status.ToString + """>" _
+ lso.Text _
+ "</LanguageString> ")
Next

writer.WriteEnd Element()
End Sub


On Sat, 08 Oct 2005 02:46:21 +0200, Pascal Schmitt wrote:
Hello!
I have nodes in the XmlDocument I create that need to be written exactly as
is - not converting < to %lt; and no changing the whitespace. (This is for
the SpreadsheetML schema and it reads the <Data> nodes literally.)


AFAIK that's not possible with XmlDocument. But XmlTextWriter has a
WriteRaw-Method.
Is it really not possible to use &lt; or <[CDATA[..]]>?
For <x>5&lt;7</x> a parser will see a text node containing "5<7".

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22593
by: Tom Pearson | last post by:
I have created an XmlDocument and can see that this is correctly formed and has a root element If I Save the doc to a file and reload it all works o If I dump the doc to a stream, again using the Save method, and write this to a file I can then reload this correctly. However since I have no need to write the data to file I want to save it as a stream then reload it the stream. However If I do this I have suddenly lost the root element ...
5
3599
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the...
1
4378
by: Ian Lawton | last post by:
Hi, in a C# app, I have an XPathDocument that looks similar to this: <row uniqueid="4234" /> <row uniqueid="4365" /> <row uniqueid="3124" /> <row uniqueid="9879" /> <row uniqueid="1332" /> <row uniqueid="4322" />
1
1249
by: Brecht Yperman | last post by:
Hi, I'd like to implement the following feature, but I don't know how: When I read in a document with 'empty' elements, i'd like them to be 'compressed'. e.g.: .... doc.LoadXml("<item><name></name></item>"); doc.Save(textWriter);
4
10994
by: Carl Williams | last post by:
Hope someone can help with this... I have looked at all the newsgroup articles and put into practice all the suggestions but to no good. I am pretty new to CSharp and .Net so any help would be greatly appreciated. I have an .ASPX.CS in which I am trying to open an XML file (which already contains content), making some alterations to the XML obtained from the file, and then trying to 'Save' the XML back to the file. I am using a...
2
16713
by: feng | last post by:
I think I didn't phrase my quetion clear enough in the last post. Here is what I need: In my VB.Net code, I already have a XML created in XMLDocument formate. I can also convert it into a string using the innerXML property of the XMLDocument object. What I want is to write this existing string, or XMLDocument, into a file, for instance, c:\test.xml. So as you can see, XMLWritter doesn't help me here,
14
2727
by: jens Jensen | last post by:
Hello, I'm calling a webmethod from a webservice written in java. I need to pass an xml file as parameter to the webmethod. I therefore use System.Xml.XmlDocument to load the xml file. The call works when i construct a string representation of the content of the xml and then, use the "loadxml" method to of Xml.XmlDocument . But it fails when i load the file directly into and System.Xml.XmlDocument
1
5947
by: James Berry | last post by:
Is there a way I can write to an XmlDocument using an XmlWriter style interface efficiently in the framework 2.0? In 1.1, you could write to a MemoryStream then load that into an XmlDocument, but this was pretty inefficient. The XmlNodeWriter sample helped here and I was expecting that to appear in the 2.0 framework but it doesn't appear to be there. Am I missing something?
3
3902
by: Stephen Ward | last post by:
I have a simple little project open a xml file change a few nodes save the file, no big deal. The problem is that the doctype is getting modified when I save the file. So it looks like this: <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> But when I save it : <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2
9276
by: yxq | last post by:
I want to add some elements to a XML file using XmlDocument, how to do? thank you very much. The original XML file like: //////////////////////////////////////////////////////// <?xml version="1.0" encoding="utf-8" ?> <AAA> <BBB> <CCC> <resource name="111">Content1</resource> <resource name="222">Content2</resource>
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.