473,785 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with loading xml from XmlTextWriter

I use an XmlTextWriter to generate xml data.

The declaration is:

System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
System.IO.Strin gWriter sw = new System.IO.Strin gWriter(sb);
XmlTextWriter w = new XmlTextWriter(s w);

And I write to it using

....
w.WriteElementS tring("foo","ba r");

When the creation is done, I need to load it into DOM to select an
XmlNode or an XmlElement to apply to another method (which I cannot
control).

I thought I could do it with:

XmlDocument xDoc = new XmlDocument();
xDoc.Load(sb.To String());
XmlNode node = xDoc.SelectSing leNode("sub-header");
XmlNode axaptaData = SomeManager.Tra nsferDataToAxap ta(node);

But at run-time I get an error saying:

"the path is too long after being fully qualified"

(when the .Load()-method is executed)

How do I get arround this?

.... and also:

The XmlTextWriter inserts the XmlDeclaration as

<?xml version="1.0" Encoding="utf-16" ?>

Is there any wy to make it write it as utf-8? I cannot apply the Encoding
as the constructor of the class, since it will then not accept my
StringWriter as first parameter.

Can you help me out with this one?

Thanks,

:o)

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.
Nov 12 '05 #1
2 2907
Jesper Stocholm wrote:

xDoc.Load(sb.To String());


Load() method accepts URL of a document to load. Use LoadXml() method to
load XML from string.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg Tkachenko [MVP] wrote :
Jesper Stocholm wrote:
xDoc.Load(sb.To String());


Load() method accepts URL of a document to load. Use LoadXml() method
to load XML from string.


Geeees, how could I miss this?

:o)

An additional question:

The Xml is in the structure:

<?xml version="1.0" ?>
<sub-header>
<header>
<field1/>
<field2/>
<line>
<fieldx/>
<fieldy/>
</line>
</header>
</sub-header>

I need to extract the entire <sub-header/>-section to an XmlNode and
pass it to another function.

I thought about doing it like this:

xDoc.LoadXml(<m y data>);
XmlNode node = xDoc.SelectSing leNode("sub-header");
SomeMethod(node );

But is there any easier way to do it? Memory-usage for the service I am
writing is essential (to limit), so if there is a more efficient way to
do it, I would prefer this.

:o)

--
Jesper Stocholm
http://stocholm.dk
Linux advocacy how-to:
http://www.datasync.com/~rogerspl/Advocacy-HOWTO-5.html
Nov 12 '05 #3

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

Similar topics

5
5893
by: Morten Nielsen | last post by:
I'm trying to load an XML file, that references a DTD without a relative URL. This renders the error: Could not find file "C:\WINNT\system32\capabilities_1_1_0.dtd". Here's the XML I'm loading: http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&REQUEST=GetCapabilities Notice the DTD reference at the second line: <!DOCTYPE WMT_MS_Capabilities SYSTEM "capabilities_1_1_0.dtd" http://www.iter.dk/contact.aspx
5
9173
by: Jain, Pranay Kumar | last post by:
Hello Everyone, I have written a simple app. that converts the dataset into excelspreadsheet. The App. uses the following architecture. First it generates the dataset with corresponding datatables(each datatable represents a worksheet).It uses an Xslt file to do the transformation of the xml (generate from dataset) and write the output xml into a xmltextwriter. The App converts the data into excel with almost all of the formatting
3
23958
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
2
7600
by: Steve | last post by:
I'm an XML newb. I'm serializing a class and when I inspect the xml file, all the data is on one line rather than being nested and indented Is that normal? <code> StreamWriter sw = new StreamWriter(m_optionsXmlFilePath, false); XmlSerializer xmlSerializer = new XmlSerializer(typeof(Options)); XmlTextWriter xmlTextWriter = new XmlTextWriter(sw);
2
5415
by: Chua Wen Ching | last post by:
Hi there, I have 2 questions to ask. 1) I have this code... XmlDocument doc = new XmlDocument(); doc.Load(myXmlPath); int maxValue = 0;
0
264
by: John George | last post by:
I am writing the file correctly and it gives me the right xml file When I read it back, I am missing one element in the last row, it sets it to the initial value before I saved the origional file? Any ideas? Thanks, I am loading the xml file with this code; Dim myFileStream As New System.IO.FileStream _ (filename, System.IO.FileMode.Create) ' Create an XmlTextWriter with the fileStream. Dim myXmlWriter As New System.Xml.XmlTextWriter _
4
3115
by: quest | last post by:
Is there anyway I can generate the xml in the following format using XmlTextWriter ? Intended output: <?xml version="1.0" ?> I tried: XmlTextWriter xmlWriter = new XmlTextWriter(xmlFileName, null); xmlWriter.Namespaces = false;
0
946
by: bissatch | last post by:
Hi, I have two files, a XML and a XSL, sitting on a LAMP server. The XSL file is dynamically created using PHP and MySQL so it must stay there. However, I want to load the files into a ASP .NET application. My ASP .NET app is as follows: <%@ Import Namespace="System.Xml" %> <%@ Import Namespace="System.Xml.Xsl" %>
3
6271
by: GaryDean | last post by:
I'm using an XmlTextWriter and it's various methods such as WriteElementString, WriteStartElement, WriteEndElement, etc to create an xml document. When I instantiate the XmlTextWriter to a file... XmlTextWriter mytw = new XmlTextWriter("c:\\temp\\myfile.xml", null) Everything writes properly and a good XML document gets created. However if I instantiate the XmlTextWriter to a memoryStream...
0
9645
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
10325
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...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.