473,395 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Opening and altering XML-doc using XmlDocument wrecks havoc on doc

Hi

I am trying to post-process some XML-documents from some third-party
software.

I open them, find the right element, manipulate the text and write it back
to the element.

Dim x As New Xml.XmlDocument
Dim nl As Xml.XmlNodeList

Dim text As String

Dim textOutput As String

x.Load(filename)

nl = x.GetElementsByTagName("text")

[snip, some manipulation of the text, not important...]

nl.Item(0).InnerText = "<![CDATA[ " & textOutput & " ]]>"

'nl.Item(0).InnerText = textOutput

x.Save("C:\Temp\XmlYt.xml")

Now, the data I write back is encoded and not enclosed in CDATA. I tried
addding the CDATA-myself, but that just gets encoded as well.
Before:
<text><![CDATA[<block><p x1="294" y1="602" x2="795" y2="1105">HORSENS - I
morgen kan være AaB's sidste dag som tophold i superligaen i denne
sæson.</p><p x1="294" y1="602" x2="795" y2="1105">AC Horsens kan sende AaB
ned fra førstepladsen, såfremt FCK to timer senere vinder hjemmekampen mod
FC Midtjylland.</p><p x1="294" y1="602" x2="795" y2="1105">AaB var et af de
svageste hold i superligaen i foråret.</p
</block>]]></text>

<text>&lt;![CDATA[ &lt;p x1="294" y1="602" x2="795" y2="1105"&gt;HORSENS - I
morgen kan være AaB's sidste dag som tophold i superligaen i denne
sæson.&lt;/p&gt;
&lt;p x1="294" y1="602" x2="795" y2="1105"&gt;AC Horsens kan sende AaB ned
fra førstepladsen, såfremt FCK to timer senere vinder hjemmekampen mod FC
Midtjylland.&lt;/p&gt;
&lt;p x1="294" y1="602" x2="795" y2="1105"&gt;AaB var et af de svageste hold
i superligaen i foråret.&lt;/p&gt;
&lt;/p&gt;
]]&gt;</text>

How do I avoid the encoding and enclose the text in CDATA-tags?
Sep 25 '06 #1
1 1302


Klaus Jensen wrote:

nl.Item(0).InnerText = "<![CDATA[ " & textOutput & " ]]>"
If you want a CDATA section then you need to do e.g.
nl.Item(0).InnerXml = "<![CDATA[ " & textOutput & " ]]>"
That is one way possible and works independent of the existing or non
existing content of that item.
If you know that the item already has exactly one child which is a CDATA
section then you can simply do
nl.Item(0).FirstChild.Value = textOutput
As for doing
x.GetElementsByTagName("text")
you might want to use
x.SelectNodes("//text")
instead due to shortcomings of .NET's implementation of GetElementsByTagName
<http://support.microsoft.com/kb/823928/en-us>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 25 '06 #2

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

Similar topics

1
by: Martin Beering | last post by:
hi to all, I do have a really big problem. I am writing a xml-file with the following vb.net.code Dim xmlfile As String = "C:\Inetpub\wwwroot\Kostenrechnung\myXML.xml" .........
0
by: Derrick | last post by:
I am opening xml files that refer to a DTD as follows: <?xml version="1.0"?><!DOCTYPE terminology SYSTEM "http://MyDomain.com/dtd/myApp.dtd"> When parsing, is there any way to get the parser...
1
by: cmrchs | last post by:
Hi, when opening an Xml-file to I want to perform validation immediately but the following does not work : DataSet m_dsProducts = new DataSet(); m_dsProducts.ReadXmlSchema("cu.xsd");...
6
by: Kenneth P | last post by:
Hi, It's rather common today, to see a PDF opening within a new Internet page. But how is it done in ASP.NET, VS2003? I'd rather use it as a way to invoice electronically. You email your...
18
by: mollyf | last post by:
I just installed SQL Server 2005 on my PC (the developer's edition) yesterday. I have some scripts written by one of my coworkers to create some tables and stored procedures in a database that...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
0
by: sushweta8 | last post by:
Hi, technology:ASP, backend: sql server I'm trying to present the sql query results in XML on my asp page, but i get an alert box saying XML: a string literal was expected, but no opening...
1
by: zufie | last post by:
Hi, I want to specifying a foreign key by altering a table. First, I create an ORDERS table without specifying a foreign key. Here is my code: CREATE TABLE ORDERS (Order_ID integer,...
2
by: doc1355 | last post by:
I have a process.php with the following code: <?php $xdoc = new DomDocument; $xdoc->Load('1.xml'); $test = $xdoc->save("2.xml"); ?> It should load 1.xml file, and saves it as 2.xml....
19
dbrewerton
by: dbrewerton | last post by:
Hello everyone, hope you are all doing fine. What I'm attempting to do and have been tearing my hair out over for the last few weeks is trying to update timestamps in my MySQL database when this data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.