473,221 Members | 1,878 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,221 software developers and data experts.

How to insert a CDATA section using XPathNavigator ?

Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-

Jun 1 '06 #1
11 6401
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-

Jun 1 '06 #2
Here is what I tried:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

and here is what I got:

<DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>

I thought that WriteCData should have kept the string as is.

Thanks for any comments.
Eric.-
"Ion Vasilian" wrote:
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-


Jun 1 '06 #3
Somehow, when I paste it here, it looks ok, but actually it looks like the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:
Here is what I tried:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

and here is what I got:

<DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>

I thought that WriteCData should have kept the string as is.

Thanks for any comments.
Eric.-
"Ion Vasilian" wrote:
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:

XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
elem.AppendChild(doc.CreateCDataSection(dataString ));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.CreateNavigator();

nav.InsertAfter(newNav);
Regards,
Eric.-


Jun 1 '06 #4
Here we go again, in notepad, I see the "<" and ">" that replace the "<" and
">" signs.
"ericms" wrote:
Somehow, when I paste it here, it looks ok, but actually it looks like the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:
Here is what I tried:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

and here is what I got:

<DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>

I thought that WriteCData should have kept the string as is.

Thanks for any comments.
Eric.-
"Ion Vasilian" wrote:
Hi Eric,

When you modify a XmlDocument via the XPathNavigator interface you sign up
for working with the XPath data model which is slightly different than the
XmlDocument. One such difference is the lack of CDATA sections which are
treated like any other plain text. Notice that the XPathNodeType enum
doesn't have a corresponding field for CDATA sections vs. XmlNodeType enum
which does.

In order for the nav.InsertAfter(newNav) operation to be successful, both
navigators should be positioned on meaningful items of the document. In the
sample code the navigators are positioned on the respective documents. Just
like in XmlDocument, you can't insert a document after a document. Most
likely you want the navigators positioned inside the respective documents:
static void Main()
{
XmlDocument docNav = new XmlDocument();
docNav.LoadXml("<root/>");
XPathNavigator nav = docNav.DocumentElement.CreateNavigator();

XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement("element");
elem.AppendChild(doc.CreateCDataSection("cdata"));
doc.DocumentElement.AppendChild(elem);
XPathNavigator newNav = doc.DocumentElement.CreateNavigator();

nav.AppendChild(newNav);
}

Once you get this far, you'll notice that the lack of CDATA sections in the
XPath data model prevents you from creating the CDATA sections through the
traversal of the navigator 'newNav'. You can get around this shortcoming if
you use a XmlWriter as input for the AppendChild():
using (XmlWriter writer = nav.AppendChild()) {
writer.WriterCData("...");
}
The CDATA sections are persisted in the XmlDocument and are observable
through the DOM API. However, through the XPathNavigator interface the CDATA
sections will be exposed as Text.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
> Can anybody show me how to insert a CDATA section using XPathNavigator ? I
> have tried the follwing with no luck:
>
> XmlDocument docNav = new XmlDocument();
> docNav.LoadXml(xmlString);
> XPathNavigator nav = docNav.CreateNavigator();
>
> XmlDocument doc = new XmlDocument();
> doc.LoadXml("<DocumentData></DocumentData>");
> XmlElement elem = doc.CreateElement(currentNodeName);
> elem.AppendChild(doc.CreateCDataSection(dataString ));
> doc.DocumentElement.AppendChild(elem);
> XPathNavigator newNav = doc.CreateNavigator();
>
> nav.InsertAfter(newNav);
>
>
> Regards,
> Eric.-
>

Jun 1 '06 #5
Hi Eric,

XmlWriter.WriteCData() will preserve the input data as expected. You
shouldn't see any escaping for '<' or '>'. In your sample code what is
'dataString'? The way you've presented the code, an exception will be thrown
at runtime since the writer created by XPathNavigator.AppendChild() will
perform wellformedness checking on the provided input. The character
sequence ']]>' is disallowed inside a CDATA section according to the XML 1.0
spec.

Just to be clear,
static void Main() {
XmlDocument document = new XmlDocument();
document.LoadXml("<root/>");
XPathNavigator navigator =
document.DocumentElement.CreateNavigator();
using (XmlWriter writer = navigator.AppendChild()) {
writer.WriteCData("some < > data");
}
document.Save(Console.Out);
}
should output:
<?xml version="1.0" encoding="IBM437"?>
<root><![CDATA[some < > data]]></root>

If you still can't get the code running, feel free to upload your project
and we'll get to the bottom of this problem.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
Here we go again, in notepad, I see the "<" and ">" that replace the "<"
and
">" signs.
"ericms" wrote:
Somehow, when I paste it here, it looks ok, but actually it looks like
the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:
> Here is what I tried:
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> and here is what I got:
>
> <DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>
>
> I thought that WriteCData should have kept the string as is.
>
> Thanks for any comments.
> Eric.-
>
>
> "Ion Vasilian" wrote:
>
> > Hi Eric,
> >
> > When you modify a XmlDocument via the XPathNavigator interface you
> > sign up
> > for working with the XPath data model which is slightly different
> > than the
> > XmlDocument. One such difference is the lack of CDATA sections which
> > are
> > treated like any other plain text. Notice that the XPathNodeType enum
> > doesn't have a corresponding field for CDATA sections vs. XmlNodeType
> > enum
> > which does.
> >
> > In order for the nav.InsertAfter(newNav) operation to be successful,
> > both
> > navigators should be positioned on meaningful items of the document.
> > In the
> > sample code the navigators are positioned on the respective
> > documents. Just
> > like in XmlDocument, you can't insert a document after a document.
> > Most
> > likely you want the navigators positioned inside the respective
> > documents:
> > static void Main()
> > {
> > XmlDocument docNav = new XmlDocument();
> > docNav.LoadXml("<root/>");
> > XPathNavigator nav =
> > docNav.DocumentElement.CreateNavigator();
> >
> > XmlDocument doc = new XmlDocument();
> > doc.LoadXml("<DocumentData></DocumentData>");
> > XmlElement elem = doc.CreateElement("element");
> > elem.AppendChild(doc.CreateCDataSection("cdata"));
> > doc.DocumentElement.AppendChild(elem);
> > XPathNavigator newNav =
> > doc.DocumentElement.CreateNavigator();
> >
> > nav.AppendChild(newNav);
> > }
> >
> > Once you get this far, you'll notice that the lack of CDATA sections
> > in the
> > XPath data model prevents you from creating the CDATA sections
> > through the
> > traversal of the navigator 'newNav'. You can get around this
> > shortcoming if
> > you use a XmlWriter as input for the AppendChild():
> > using (XmlWriter writer = nav.AppendChild()) {
> > writer.WriterCData("...");
> > }
> > The CDATA sections are persisted in the XmlDocument and are
> > observable
> > through the DOM API. However, through the XPathNavigator interface
> > the CDATA
> > sections will be exposed as Text.
> >
> > Ion
> >
> > "ericms" <er****@discussions.microsoft.com> wrote in message
> > news:A5**********************************@microsof t.com...
> > > Can anybody show me how to insert a CDATA section using
> > > XPathNavigator ? I
> > > have tried the follwing with no luck:
> > >
> > > XmlDocument docNav = new XmlDocument();
> > > docNav.LoadXml(xmlString);
> > > XPathNavigator nav = docNav.CreateNavigator();
> > >
> > > XmlDocument doc = new XmlDocument();
> > > doc.LoadXml("<DocumentData></DocumentData>");
> > > XmlElement elem = doc.CreateElement(currentNodeName);
> > > elem.AppendChild(doc.CreateCDataSection(dataString ));
> > > doc.DocumentElement.AppendChild(elem);
> > > XPathNavigator newNav = doc.CreateNavigator();
> > >
> > > nav.InsertAfter(newNav);
> > >
> > >
> > > Regards,
> > > Eric.-
> > >
> >
> >
> >

Jun 2 '06 #6
In my sample code, 'dataString' is an encoded string. As requested by our
verndor that we send a copy of PDF file encoded, in short should look similar
like:
<DocumentData><![CDATA[Mzc4MDY4Nz........]]></DocumentData>
With the following sample code:

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData(dataString);
}

The ouput is fine except that it is missing the <![CDATA[.

And when I did the following :

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

Everything is fine except that the "less than" sign is replaced with
ampersand, lt, semicolon and the greater sign is replaced with ampersand, gt,
semicolon.

I am home now, I don't have a copy of the project with me now.

"Ion Vasilian" wrote:
Hi Eric,

XmlWriter.WriteCData() will preserve the input data as expected. You
shouldn't see any escaping for '<' or '>'. In your sample code what is
'dataString'? The way you've presented the code, an exception will be thrown
at runtime since the writer created by XPathNavigator.AppendChild() will
perform wellformedness checking on the provided input. The character
sequence ']]>' is disallowed inside a CDATA section according to the XML 1.0
spec.

Just to be clear,
static void Main() {
XmlDocument document = new XmlDocument();
document.LoadXml("<root/>");
XPathNavigator navigator =
document.DocumentElement.CreateNavigator();
using (XmlWriter writer = navigator.AppendChild()) {
writer.WriteCData("some < > data");
}
document.Save(Console.Out);
}
should output:
<?xml version="1.0" encoding="IBM437"?>
<root><![CDATA[some < > data]]></root>

If you still can't get the code running, feel free to upload your project
and we'll get to the bottom of this problem.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
Here we go again, in notepad, I see the "<" and ">" that replace the "<"
and
">" signs.
"ericms" wrote:
Somehow, when I paste it here, it looks ok, but actually it looks like
the
following in Notepad:

<DocumentData><![CDATA[Mzc4MDY4Nz....]]></DocumentData>


"ericms" wrote:

> Here is what I tried:
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> and here is what I got:
>
> <DocumentData><![CDATA[Mzc4MDY4NzA....]]></DocumentData>
>
> I thought that WriteCData should have kept the string as is.
>
> Thanks for any comments.
> Eric.-
>
>
> "Ion Vasilian" wrote:
>
> > Hi Eric,
> >
> > When you modify a XmlDocument via the XPathNavigator interface you
> > sign up
> > for working with the XPath data model which is slightly different
> > than the
> > XmlDocument. One such difference is the lack of CDATA sections which
> > are
> > treated like any other plain text. Notice that the XPathNodeType enum
> > doesn't have a corresponding field for CDATA sections vs. XmlNodeType
> > enum
> > which does.
> >
> > In order for the nav.InsertAfter(newNav) operation to be successful,
> > both
> > navigators should be positioned on meaningful items of the document.
> > In the
> > sample code the navigators are positioned on the respective
> > documents. Just
> > like in XmlDocument, you can't insert a document after a document.
> > Most
> > likely you want the navigators positioned inside the respective
> > documents:
> > static void Main()
> > {
> > XmlDocument docNav = new XmlDocument();
> > docNav.LoadXml("<root/>");
> > XPathNavigator nav =
> > docNav.DocumentElement.CreateNavigator();
> >
> > XmlDocument doc = new XmlDocument();
> > doc.LoadXml("<DocumentData></DocumentData>");
> > XmlElement elem = doc.CreateElement("element");
> > elem.AppendChild(doc.CreateCDataSection("cdata"));
> > doc.DocumentElement.AppendChild(elem);
> > XPathNavigator newNav =
> > doc.DocumentElement.CreateNavigator();
> >
> > nav.AppendChild(newNav);
> > }
> >
> > Once you get this far, you'll notice that the lack of CDATA sections
> > in the
> > XPath data model prevents you from creating the CDATA sections
> > through the
> > traversal of the navigator 'newNav'. You can get around this
> > shortcoming if
> > you use a XmlWriter as input for the AppendChild():
> > using (XmlWriter writer = nav.AppendChild()) {
> > writer.WriterCData("...");
> > }
> > The CDATA sections are persisted in the XmlDocument and are
> > observable
> > through the DOM API. However, through the XPathNavigator interface
> > the CDATA
> > sections will be exposed as Text.
> >
> > Ion
> >
> > "ericms" <er****@discussions.microsoft.com> wrote in message
> > news:A5**********************************@microsof t.com...
> > > Can anybody show me how to insert a CDATA section using
> > > XPathNavigator ? I
> > > have tried the follwing with no luck:
> > >
> > > XmlDocument docNav = new XmlDocument();
> > > docNav.LoadXml(xmlString);
> > > XPathNavigator nav = docNav.CreateNavigator();
> > >
> > > XmlDocument doc = new XmlDocument();
> > > doc.LoadXml("<DocumentData></DocumentData>");
> > > XmlElement elem = doc.CreateElement(currentNodeName);
> > > elem.AppendChild(doc.CreateCDataSection(dataString ));
> > > doc.DocumentElement.AppendChild(elem);
> > > XPathNavigator newNav = doc.CreateNavigator();
> > >
> > > nav.InsertAfter(newNav);
> > >
> > >
> > > Regards,
> > > Eric.-
> > >
> >
> >
> >


Jun 2 '06 #7


ericms wrote:

And when I did the following :

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

Everything is fine except that the "less than" sign is replaced with
ampersand, lt, semicolon and the greater sign is replaced with ampersand, gt,
semicolon.


Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 2 '06 #8
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:


ericms wrote:

And when I did the following :

using (XmlWriter writer = nav.AppendChild())
{
writer.WriteCData("<![CDATA[" + dataString + "]]>");
}

Everything is fine except that the "less than" sign is replaced with
ampersand, lt, semicolon and the greater sign is replaced with ampersand, gt,
semicolon.


Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jun 2 '06 #9
Hi Eric,

Can you describe how you determined if it worked or not? Are you listing an
output file or maybe you just look for the expected data through
XPathNavigator. As I explained before, in the context of XPathNavigator a
CDATA section will surface as Text plus the markup (ie. "<![CDATA[", "]]>")
will be missing from the observable value.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:


ericms wrote:

> And when I did the following :
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> Everything is fine except that the "less than" sign is replaced with
> ampersand, lt, semicolon and the greater sign is replaced with
> ampersand, gt,
> semicolon.


Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jun 2 '06 #10
When I am done, I do the following:

string dataOut = navigator.OuterXml;
textBox1.Text = dataOut;

I check the output in the content of TextBox. There is where I don't see
the <![CDATA]]> delimiters.

"Ion Vasilian" wrote:
Hi Eric,

Can you describe how you determined if it worked or not? Are you listing an
output file or maybe you just look for the expected data through
XPathNavigator. As I explained before, in the context of XPathNavigator a
CDATA section will surface as Text plus the markup (ie. "<![CDATA[", "]]>")
will be missing from the observable value.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:


ericms wrote:
> And when I did the following :
>
> using (XmlWriter writer = nav.AppendChild())
> {
> writer.WriteCData("<![CDATA[" + dataString + "]]>");
> }
>
> Everything is fine except that the "less than" sign is replaced with
> ampersand, lt, semicolon and the greater sign is replaced with
> ampersand, gt,
> semicolon.

Simply do
writer.WriteCData(dataString);
do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
add them directly when WriteCData is executed.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Jun 2 '06 #11
I know what my problem is. I should have done the following:

string dataOut = document.OuterXml;
textBox1.Text = dataOut;

I should have used the OuterXml of the Document, not the Navigator.


"ericms" wrote:
When I am done, I do the following:

string dataOut = navigator.OuterXml;
textBox1.Text = dataOut;

I check the output in the content of TextBox. There is where I don't see
the <![CDATA]]> delimiters.

"Ion Vasilian" wrote:
Hi Eric,

Can you describe how you determined if it worked or not? Are you listing an
output file or maybe you just look for the expected data through
XPathNavigator. As I explained before, in the context of XPathNavigator a
CDATA section will surface as Text plus the markup (ie. "<![CDATA[", "]]>")
will be missing from the observable value.

Ion

"ericms" <er****@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
I have tried it and the following did not work:
writer.WriteCData(dataString);
It did not add the <![CDATA]]> demiliters as you indicated.

I am using VisualStudio 2005, .NET 2.0.
Thanks,
Eric.-

"Martin Honnen" wrote:

>
>
> ericms wrote:
>
>
> > And when I did the following :
> >
> > using (XmlWriter writer = nav.AppendChild())
> > {
> > writer.WriteCData("<![CDATA[" + dataString + "]]>");
> > }
> >
> > Everything is fine except that the "less than" sign is replaced with
> > ampersand, lt, semicolon and the greater sign is replaced with
> > ampersand, gt,
> > semicolon.
>
> Simply do
> writer.WriteCData(dataString);
> do _not_ write out the <![CDATA]]> demiliters yourself, the writer will
> add them directly when WriteCData is executed.
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
>


Jun 2 '06 #12

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

Similar topics

8
by: Xah Lee | last post by:
what does it mean when a style tag gives something like the following? <style type="text/css" media="screen,projection">/*<!]>*/</style> is this standard? Xah xah@xahlee.org ∑...
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
2
by: C | last post by:
Hi, I have an XML doc as below <WebSRFTemplate Version="1" Type="SERVICE"> <Data> <Field Name="SERVICEStaticRoute2IPnetwork1"><!]></Field> </Data> </WebSRFTemplate>
2
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL...
1
by: soccerdad | last post by:
I've got a class hierarchy generated from a .xsd schema file using the XSD.EXE tool. One of the elements will have its "inner text" set to a CDATA block. The XSD.EXE tool exposed a "Value" property...
2
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is...
18
by: sim.sim | last post by:
Hi all. i'm faced to trouble using minidom: #i have a string (xml) within CDATA section, and the section includes "\r\n": iInStr = '<?xml version="1.0"?>\n<Data><!]></Data>\n' #After i...
1
by: Dariusz Tomo | last post by:
Hi, I have got xml document with CDATA sections containing special characters like links to images. All Iwant is to display the content in my div section. I tried like this: protected...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.