|
XML has five predefined entities that cannot exist in parsed character data. These are:So, if you have an XML file with one of those in the parsed character data, then you do not have a valid XML document. For example:
Correct XML
<a>Bob & Jane went to "work"</a>
Incorrect XML
<a>Bob & Jane went to "work"</a> XML does allow for a way "around" this, of course.
<a><![CDATA[Bob & Jane went to "work"]]></a> The CDATA means unparsed character data, in its raw state. Try using that.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi Curtis,
Thanks for getting back to me. The following is a sample of my xml file. I am not sure where in it I would add the CDATA. I tried <file name="<![CDATA["File" with="" &="" character.doc"]]=""> but it did not seem to like it very much.
<vfs path="efmROOT">
<file name="File Name with & character.doc" size="29" origpath="\\server1\g$\data\data\File Name with & character.doc">
Thanks
|
|
|
|
|
Next time, check the "Ignore HTML tags in this message (good for code snippets)" checkbox so that the XML shows up! <smile />
Okay, I didn't understand that the string existed in a tag's attribute. So, just replace the & with a &. Like:
<myTag attribute1="this & that" />
The CDATA thing only works for tag values, that is, entries between open and close tags. Never, ever in attribute values.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you. It works fine now.
|
|
|
|
|
Excellent! Happy coding.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi,
I am new to XML and C#. I want to load this XML via the below code to an XmlDocument but it returns an Error which I don't know how to handle it. Here is the XML:
<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:iana:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg lang="en-US">Command completed successfully</msg>
</result>
<resData>
<contact:creData>
<contact:id>Epp1464</contact:id>
</contact:creData>
</resData>
<trID>
<clTRID>CrtContact0031</clTRID>
<svTRID>CrtContact0031-OLNIC-SRV</svTRID>
</trID>
<chksum>979170f7c148e945e352c7d155da8ac2</chksum>
</response>
</epp>
And here is my code. Actually I need also to know how to get the <contact:id> and <result> node bvalue and attribue.
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXMLSrc);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Please help.
Samy
-- modified at 8:33 Wednesday 11th January, 2006
|
|
|
|
|
Anybody help me!
My wordml has the following styles:
w:p[w:pPr/w:pStyle[@w:val='authors']]
w:r[w:rPr/w:rStyle[@w:val='csfname']
w:r[w:rPr/w:rStyle[@w:val='csmidname']
w:r[w:rPr/w:rStyle[@w:val='cssurname']
w:p[w:pPr/w:pStyle[@w:val='affiliation']]
w:r[w:rPr/w:rStyle[@w:val='orgname']
w:r[w:rPr/w:rStyle[@w:val='city']
w:r[w:rPr/w:rStyle[@w:val='country']
I want to group the 3 different character styles under
"author" and another 3 different character styles
under "affiliation" and also group 2 paragraph styles
-- authors and affilition under authorgrp. I want the
output like:
<authorgrp>
<author>
<fname>aaaaaaaaa</fname>
<midname>cccccccc</midname>
<surname>bbbbbbbb</surname>
</author>
<affiliation>
<orgname>mmmmmmmm</orgname>
<city>nnnnnnnnn</city>
<country>ooooooooo</country>
</affiliation>
</authorgrp>
|
|
|
|
|
Summary Question: How can I do pointer fix uping using XML Serialization?
I'm getting tripped up over one idea when performming XML serialization.
Lets say I have a simple class structure where Students have Teachers.
<br />
class Teacher<br />
{<br />
public string name;<br />
}<br />
<br />
class Student<br />
{<br />
public Teacher mTeacher;<br />
}<br />
<br />
main<br />
{<br />
Teacher teacher = new Teacher();<br />
teacher.name = "Mr Smith";<br />
<br />
Student [] students = new Student[2];<br />
<br />
students[0] = new Student();<br />
students[1] = new Student();<br />
<br />
students[0].mTeacher = teacher;<br />
students[1].mTeacher = teacher;<br />
<br />
...<br />
<br />
SERIALIZE students[]<br />
...<br />
DESERIALIZE students[]<br />
<br />
}<br />
What I'm finding is that when I serialize/deserialize, I'll find that each student has their own unique teacher "Mr Smith" rather than both students sharing the same teacher.
When I do this kind of serialization using a BinaryFormatter I find that the teacher is not created twice and that the serializer realizes that this object has already been serialized and essentially stores a pointer and when the object is serialized, that pointer is fixed up.
Summary Question: How can I do pointer fix uping using XML Serialization?
|
|
|
|
|
I have an XmlDocument that I use with an XmlTransform that generates some HTML with a javascript section. The javascript has an if ( a < b){} in it, but that is really confusing the transform processor.
I found a document that suggested that the correct way is to use this construction:
<xsl:text disable-output-escaping="yes"><</xsl:text> However, all that happens is that it confuses the parser. I get the following exception when XmlTransform.Load() is called: This is an unexpected token. The expected token is 'NAME'. Line 23, position 63.
Other options I've tried tend to output < which causes a runtime error when that piece of javascript is run.
Does anyone have any ideas of how to fix this?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Okay - So I'm fed up trying to figure this out and I've got a quick and dirty workaround (and since it is only a prototype I'm not so fussed - but if anyone has any insight I'd like to know for future reference).
Anyway, when the transform processor returns the string back I just use:
html = html.Replace("<", "<"); Now it works. It's ugly - but it produces the desired output.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
I hope this helps. You can just plop it down into the Main method of a Console application and add the appropriate using statements. If I haven't understood the problem, maybe I could help a little more with another explanation.
string inputXmlPath = @"input.xml";
string inputXslPath = @"input.xsl";
string outputFilePath = @"output.html";
string inputXml = @"<one><two><three><![CDATA[if( a < b ) {}]]></three></two></one>";
string inputXsl = @"<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">" +
@"<xsl:template match=""three"">" +
@"<script>" +
@"<xsl:value-of disable-output-escaping=""yes"" select="".""/>" +
@"</script>" +
@"</xsl:template>" +
@"</xsl:stylesheet>";
StreamWriter sw = File.CreateText( inputXmlPath );
sw.Write( inputXml );
sw.Close();
sw = File.CreateText( inputXslPath );
sw.Write( inputXsl );
sw.Close();
try
{
XslTransform trans = new XslTransform();
trans.Load( inputXslPath );
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
trans.Transform( inputXmlPath, outputFilePath, resolver );
}
catch( Exception e )
{
Console.WriteLine( e.Message );
Console.WriteLine( e.StackTrace );
}
File.Delete( inputXmlPath );
File.Delete( inputXslPath );
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I've tried something like this, but it didn't work. Although the value with the < didn't come from the XML file, it was in the XSL file.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Oh, sorry! How about this? It actually makes a nice HTML file. The importan part, I think, is highlighted in yellow.
string inputXmlPath = @"input.xml";
string inputXslPath = @"input.xsl";
string outputPath = @"output.html";
string inputXml = @"<sur name=""flanders""><c name=""ned"" /><c name=""maude"" /><c name=""rod"" /><c name=""todd"" /></sur>";
string inputXsl = @"<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">" +
@"<xsl:template match=""/"">" +
@"<html><head><title>Homer's Neighbors</title></head>" +
@"<body>" +
@"<h1><xsl:value-of select=""@name"" /></h1>" +
@"<xsl:apply-templates />" +
@"</body>" +
@"</html>" +
@"</xsl:template>" +
@"<xsl:template match=""c"">" +
@"<script> <span style="background-color:yellow">if( ""<xsl:value-of select=""@name"" />"".length <xsl:text disable-output-escaping=""yes""><![CDATA[<]]></xsl:text> 4 )</span> alert( ""<xsl:value-of select=""@name"" />"" );</script>" +
@"</xsl:template>" +
@"</xsl:stylesheet>";
StreamWriter sw = File.CreateText( inputXmlPath );
sw.Write( inputXml );
sw.Close();
sw = File.CreateText( inputXslPath );
sw.Write( inputXsl );
sw.Close();
XslTransform trans = new XslTransform();
trans.Load( inputXslPath );
XmlUrlResolver resolver = new XmlUrlResolver();
trans.Transform( inputXmlPath, outputPath, resolver );
File.Delete( inputXmlPath );
File.Delete( inputXslPath );
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I am a student and have been given the following question using XML. I have never used XML before. I have looked through tutorials and they confuse me! I would really appreciate it if any XML experts out there could help me, just to get me on the right track and so I understand what i'm doing. My assignment question is:
You are required to demonstrate your understanding of the XML technologies studied through the production (publishing) of two sets of static html pages using XSL techniques and multiple XML data source(s). Each set of static html pages must:
• provide a default opening page linking to other pages as relevant.
• provide a sample of online trading pages.
• comprise a minimum of four categories/sections, each comprising a minimum of four sub-categories/sub-sections.
• be produced using a suitable XSLT 2.0 compatible engine/utility/IDE.
• be based upon a common xml file denoting the category/sub-category structure called structure.xml.
• be based upon a common xml file denoting the product details called products.xml.
• be produced using an appropriate unique xml style sheet.
You may/should create categories and sub-categories for products of your own choosing. This will form the basis of the navigation through your published pages. Your selection should reflect a single overall theme. Sample product content is therefore left to the student as part of the exercise.
The production of both structure.xml and products.xml may involve the use of products such as MS Wordpad and MS Notepad. It is therefore necessary to provide suitable XML Schema files to ensure that the xml files used in the publishing are both well-formed and valid:
• Schema file for structure.xml provided in structure.xsd
• Schema file for products.xml provided in products.xsd
The implemented XSL stylesheet(s) will make use of multiple output files and multiple XML input sources.
PLEASE HELP ME!
Ross
|
|
|
|
|
R0ssini wrote: I have never used XML before
R0ssini wrote: demonstrate your understanding of the XML technologies studied
What's wrong with this picture ?
Your post sounds as if you have absolutely no idea how to do this. I'm sure this is not true. Which bits are you stuck on ? Can you create HTML ? Can you create a basic XML document ? I'm assuming that XSLT is at least part of the problem. If you google 'xslt reference' you will find some great links, the third one is a PDF you should download and keep, I still use it from time to time.
Beyond that, you need to explain just how basic a help you need, and if you need to know how to create an XML file, why you've been given this assignment
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for the reply. Without meaning to sound completely dull, as I have said I have never used XML before. Looking through tutorials, there's examples of creating a web page using XML language, but, for instance, if I copy and paste the code into notepad, I then have no idea how to bring the code up as a web page. I did a small bit of HTML 3 years ago and I know XML is similar, but i've forgotton even the most basic things! So basically, imagine i'm a complete novice who has never used XML before. How do I set up a basic web page using XML language? Any help would be greatly appreciated
|
|
|
|
|
If you create a html page, you need to give it a .html extension, instead of .txt. Then, double click on the file, IE will open it.
Basically, creating a web page using XML just means you use XHTML, which in turn essentially means that the HTML needs to be XML. This is HTML, but not XML
one line<br>another line
That is because the <br> tag is never closed. To solve this, do this instead:
one line<br/>another line
this is another example:
this <strong>text has <em>some bold</strong> and </em>some italics
strong and em are the recommended tags, they replace b and i, from memory ( years since I used them ). This is not valid XML as the tags do not line up. To replace this, you'd need to work out a solution where the tags do not next. The following would not look the same, but illustrates the idea:
this <strong>text has <em>some bold</em> and </strong>some italics
So - all you need to do is create an HTML page that is entirely XML compiliant. An easy way to make sure is to download XML Spy Home Edition, it is a half decent XML editor. It will also help you with writing XSLTs, which are transformations on XML to produce a new document which may or may not be XML.
So, if you've not done XML for years, why are you doing an assignment on XML ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for your help. I will have a go at it now and let you know how i'm doing. I'm taking a course called Computer Studies and there's 6 modules in the course. The course contains a mixture of everything, 1 module is database development, another is web design and so on. The module i'm doing at the moment is advanced internet development and this assignment happens to be on XML. My lecturer is useless and all he's said is to search for tutorials to help.
I have managed to get the XML text displayed in the browser so that's a start, at least i'm making progress! Now I can do that, i'll concentrate on writing some code to help me create a default opening page. I suppose i'll have to look through more tutorials to help me with that! Thanks for your help so far
|
|
|
|
|
No worries - sounds like you're on the right track. Ask again if you need help.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you Christian, really appreciate it
|
|
|
|
|
Christian, I have found a good example of a CD catalog I may use to help me. The code is as follows:
-
- <catalog>
- <cd>
<title>Empire Burlesque
<artist>Bob Dylan
<country>USA
<company>Columbia
<price>10.90
<year>1985
- <cd>
<title>Hide your heart
<artist>Bonnie Tyler
<country>UK
<company>CBS Records
<price>9.90
<year>1988
- <cd>
<title>Greatest Hits
<artist>Dolly Parton
<country>USA
<company>RCA
<price>9.90
<year>1982
- <cd>
<title>Still got the blues
<artist>Gary Moore
<country>UK
<company>Virgin records
<price>10.20
<year>1990
- <cd>
<title>Eros
<artist>Eros Ramazzotti
<country>EU
<company>BMG
<price>9.90
<year>1997
- <cd>
<title>One night only
<artist>Bee Gees
<country>UK
<company>Polydor
<price>10.90
<year>1998
- <cd>
<title>Sylvias Mother
<artist>Dr.Hook
<country>UK
<company>CBS
<price>8.10
<year>1973
- <cd>
<title>Maggie May
<artist>Rod Stewart
<country>UK
<company>Pickwick
<price>8.50
<year>1990
- <cd>
<title>Romanza
<artist>Andrea Bocelli
<country>EU
<company>Polydor
<price>10.80
<year>1996
- <cd>
<title>When a man loves a woman
<artist>Percy Sledge
<country>USA
<company>Atlantic
<price>8.70
<year>1987
- <cd>
<title>Black angel
<artist>Savage Rose
<country>EU
<company>Mega
<price>10.90
<year>1995
- <cd>
<title>1999 Grammy Nominees
<artist>Many
<country>USA
<company>Grammy
<price>10.20
<year>1999
- <cd>
<title>For the good times
<artist>Kenny Rogers
<country>UK
<company>Mucik Master
<price>8.70
<year>1995
- <cd>
<title>Big Willie style
<artist>Will Smith
<country>USA
<company>Columbia
<price>9.90
<year>1997
- <cd>
<title>Tupelo Honey
<artist>Van Morrison
<country>UK
<company>Polydor
<price>8.20
<year>1971
- <cd>
<title>Soulsville
<artist>Jorn Hoel
<country>Norway
<company>WEA
<price>7.90
<year>1996
- <cd>
<title>The very best of
<artist>Cat Stevens
<country>UK
<company>Island
<price>8.90
<year>1990
- <cd>
<title>Stop
<artist>Sam Brown
<country>UK
<company>A and M
<price>8.90
<year>1988
- <cd>
<title>Bridge of Spies
<artist>T'Pau
<country>UK
<company>Siren
<price>7.90
<year>1987
- <cd>
<title>Private Dancer
<artist>Tina Turner
<country>UK
<company>Capitol
<price>8.90
<year>1983
- <cd>
<title>Midt om natten
<artist>Kim Larsen
<country>EU
<company>Medley
<price>7.80
<year>1983
- <cd>
<title>Pavarotti Gala Concert
<artist>Luciano Pavarotti
<country>UK
<company>DECCA
<price>9.90
<year>1991
- <cd>
<title>The dock of the bay
<artist>Otis Redding
<country>USA
<company>Atlantic
<price>7.90
<year>1987
- <cd>
<title>Picture book
<artist>Simply Red
<country>EU
<company>Elektra
<price>7.20
<year>1985
- <cd>
<title>Red
<artist>The Communards
<country>UK
<company>London
<price>7.80
<year>1987
- <cd>
<title>Unchain my heart
<artist>Joe Cocker
<country>USA
<company>EMI
<price>8.20
<year>1987
However, when I try loading this in IE, shouldn't IE be able to render these XML files? Shouldn't there be red + and - symbols which when clicked expand/collapse the contents? The code is found at the following link: www.w3schools.com/xml/cd_catalog.xml. But when I try copying it into notepad or wordpad the + and - symbols go missing Help please!
|
|
|
|
|
Strange, the titles have gone missing. here it is again properly:
-
<catalog>
<cd>
<title>Empire Burlesque
<artist>Bob Dylan
<country>USA
<company>Columbia
<price>10.90
<year>1985
<cd>
<title>Hide your heart
<artist>Bonnie Tyler
<country>UK
<company>CBS Records
<price>9.90
<year>1988
<cd>
<title>Greatest Hits
<artist>Dolly Parton
<country>USA
<company>RCA
<price>9.90
<year>1982
<cd>
<title>Still got the blues
<artist>Gary Moore
<country>UK
<company>Virgin records
<price>10.20
<year>1990
<cd>
<title>Eros
<artist>Eros Ramazzotti
<country>EU
<company>BMG
<price>9.90
<year>1997
<cd>
<title>One night only
<artist>Bee Gees
<country>UK
<company>Polydor
<price>10.90
<year>1998
<cd>
<title>Sylvias Mother
<artist>Dr.Hook
<country>UK
<company>CBS
<price>8.10
<year>1973
<cd>
<title>Maggie May
<artist>Rod Stewart
<country>UK
<company>Pickwick
<price>8.50
<year>1990
<cd>
<title>Romanza
<artist>Andrea Bocelli
<country>EU
<company>Polydor
<price>10.80
<year>1996
<cd>
<title>When a man loves a woman
<artist>Percy Sledge
<country>USA
<company>Atlantic
<price>8.70
<year>1987
<cd>
<title>Black angel
<artist>Savage Rose
<country>EU
<company>Mega
<price>10.90
<year>1995
<cd>
<title>1999 Grammy Nominees
<artist>Many
<country>USA
<company>Grammy
<price>10.20
<year>1999
<cd>
<title>For the good times
<artist>Kenny Rogers
<country>UK
<company>Mucik Master
<price>8.70
<year>1995
<cd>
<title>Big Willie style
<artist>Will Smith
<country>USA
<company>Columbia
<price>9.90
<year>1997
<cd>
<title>Tupelo Honey
<artist>Van Morrison
<country>UK
<company>Polydor
<price>8.20
<year>1971
<cd>
<title>Soulsville
<artist>Jorn Hoel
<country>Norway
<company>WEA
<price>7.90
<year>1996
<cd>
<title>The very best of
<artist>Cat Stevens
<country>UK
<company>Island
<price>8.90
<year>1990
<cd>
<title>Stop
<artist>Sam Brown
<country>UK
<company>A and M
<price>8.90
<year>1988
<cd>
<title>Bridge of Spies
<artist>T'Pau
<country>UK
<company>Siren
<price>7.90
<year>1987
<cd>
<title>Private Dancer
<artist>Tina Turner
<country>UK
<company>Capitol
<price>8.90
<year>1983
<cd>
<title>Midt om natten
<artist>Kim Larsen
<country>EU
<company>Medley
<price>7.80
<year>1983
<cd>
<title>Pavarotti Gala Concert
<artist>Luciano Pavarotti
<country>UK
<company>DECCA
<price>9.90
<year>1991
<cd>
<title>The dock of the bay
<artist>Otis Redding
<country>USA
<company>Atlantic
<price>7.90
<year>1987
<cd>
<title>Picture book
<artist>Simply Red
<country>EU
<company>Elektra
<price>7.20
<year>1985
<cd>
<title>Red
<artist>The Communards
<country>UK
<company>London
<price>7.80
<year>1987
<cd>
<title>Unchain my heart
<artist>Joe Cocker
<country>USA
<company>EMI
<price>8.20
<year>1987
|
|
|
|
|
For some reason the <cd> titles etc aren't copying. If you could just type http://www.w3schools.com/xml/cd_catalog.xml into your browser you will see what code I am on about. I copy it into notepad, save it as a .html file, but when I try opening it up in IE, the XML files aren't rendered, there's no red + and - symbols like there should be?
|
|
|
|
|
Hi R0ssini,
Read the following article to get a good hand on your xml basics. This handbook is meant for novice xml programmers.
I am sure this will help you clear the basics to some extent. If you have any further queries, do email us. We shall get back to you with solution.
regards,
Itech
Itech Consulting
www.itechconsulting.co.in
|
|
|
|
|
Hi R0ssini,
Forgot to post you the link in our earlier mail. Its -
www.codeproject.com/useritems/XML_Basics.asp
regards,
Itech Consulting
Itech Consulting
www.itechconsulting.co.in
|
|
|
|