|
I lost a few hours to this problem this morning, and after I discovered the workaround I felt like ranting, but now I've cooled down a bit (and had a beer).
Anyway... I have an XML file with embedded stylesheets (XSL). One of these stylesheets transforms the XML to CSV. An important part of this transform is the insertion of linefeeds, I do this with <xsl:text> </xsl:text> , and it worked fine until I started using an XmlReader to perform a validated read.
This works; the resultant XmlElement's text is a linefeed.
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
doc.Load ( @"\XMLtest.xml" ) ;
This doesn't work; the resultant XmlElement's text is empty.
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
System.Xml.XmlReaderSettings rs = new System.Xml.XmlReaderSettings() ;
(set the XmlReaderSetting's properties.)
doc.Load ( System.Xml.XmlReader.Create ( @"\XMLtest.xml" , rs ) ) ;
So then, looking through the help for XmlReader I see:
XmlReader objects created by the Create method expand all entities automatically.
So I assume that the entity gets expanded, then the linefeed (whitespace) is determined to be non-essential and removed, leaving an empty value.
Looking further I see:
If you must expand entities on request (readers created by the Create method expand all entities), or if you do not want your text content normalized, use the XmlTextReader class.
Now wait a minute! Isn't the XmlTextReader, not recommended practice?
In the Microsoft .NET Framework version 2.0 release, the recommended practice is to create XmlReader instances using the System.Xml.XmlReader.Create method.
XmlReader objects created by the Create method are, by default, more conformant than the XmlTextReader implementation.
So the workaround I chose is:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
System.Xml.XmlReaderSettings rs = new System.Xml.XmlReaderSettings() ;
(set the XmlReaderSetting's properties.)
doc.Load ( System.Xml.XmlReader.Create ( new System.Xml.XmlTextReader ( @"\XMLtest.xml" ) , rs ) ) ;
It gets the job done, but it seems odd that there isn't a property in the XmlReaderSettings to do this. I tried the IgnoreWhitespace and CheckCharacters properties but to no avail.
My question is: Does .net 3.0 solve this issue? Does anyone else have cleaner workaround?
|
|
|
|
|
I think you may need to use the xml:space attribute in you XML document. It has two values, "default" and "preserve". "default" value tells the XML processor to handle space as necessary. Also, this is the default behavior of the processor. "preserve" means to maintain whitespace as is. Also, is not an entity, and > is an entity.
Example:
<poem xml:space="preserve">
... all whitespace will be preserved in all child nodes(remember text is considered a node) ...
<poem/>
Unfortunately, I found the following: http://www.stylusstudio.com/xmldev/200307/post70060.html#[^]
-- modified at 20:16 Friday 1st June, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I'll give that a try, thanks.
|
|
|
|
|
George L. Jackson wrote: Also, is not an entity, and > is an entity.
It's character reference[^]! Awesome, I didn't know there is difference between them till now.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
hi,
How can i create XSD from XML document programmatically in C#?
Also is there a tool available to achieve this?
|
|
|
|
|
If you have Visual Studio 2005, you just open up an XML file and there will be a XML Menu with a menu item, "Create Schema". Also, a toolbar button to create a schema may also appear. I believe this works in Standard and above. However, I am not sure about Express.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
AmitG77 wrote:
Also is there a tool available to achieve this?
XML Schema Definition Tool (Xsd.exe)[^]
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
I am trying to create an Excel file with the XMLTextWriter class. I am successfully able to write the excel file with data from dataset in it. But the problem is that the string data being written in Excel is not visible fully in the cells.
I tried the option of AutoFitWidth="1", But it does not comes into effect for String data. I also got some clue for using System.Drawing.Graphics.MeasureString method. But I am not able to use it in Web project.
Can anyone guide me as to how can I fit the width of the string text in excel cell programatically.
If my mind can conceive it, and my heart can believe it, I know I can achieve it.
|
|
|
|
|
I don't know much about spreadsheetML, but if I recall autofit is a property of the column and not the cell. Are you setting it as a column property?
Sorry, but if that doesn't fix the problem I really don't know what will. I don't normally jump into a topic I don't know that well, but since no one else has answered I thought I'd throw my hat in.
|
|
|
|
|
I've been using XML and schemas for a while now, but have never really read up on it or been shown officially how to use it. Does anyone know of a good book on creating Schemas? Or good concise info on the net about it?
While you're at it, can anyone point me in the direction of how to make up patterns (simple and complicated) in a schema, so that the xml data can be accurately validated against it.
Thanks in advance,
Jugs
|
|
|
|
|
How can I retrieve the data from XML file using SQL query is there any
Data driver like ODBC or other tool , application,….
Please advice
Charbel
|
|
|
|
|
|
HI guys,
I have one query, I have one URL using that URL how can i send XML request and get XML response? is it possible? if it is possible please tell me how? i am so new for this concept so i dont know how work. please help me.. iam working in asp.net with Vb 1.1 so please help me..
Thanking you nad regards,
Praveen Kumar..
Praveen Kumar.R
|
|
|
|
|
|
Hi guys,
I'm using XmlFormView control to display an InfoPath form inside a custom aspx page. In order to load the form I can use XmlLocation which rapresents an Url to the .xml file. Does anyone know if it could be possible to inject Xml from memory (for example from a memory stream) instead of accessing the xml file? In other words I need to have the property XmlFormView.XmlForm setted without setting the XmlLocation property.
Thank you in advance.
Stefano
|
|
|
|
|
Hi
I am doing an application in which I am using a XML file to populate a datagrid.
In that XML file I have one like.....
<>
1.To generate leads efficiently and profitably.
2.To ensure that all details are collected in one call.
3.To provide email and chat support.
4.To manage Work Basket reports as required.
5.To meet targets for both quantity and quality.
<>
When I am trying to populate this column onto datagrid, all these lines or sentences are getting combine and displaying like a paragraph.
I want to know how to format this column to get them in the a new line
Thank u
Chandu
|
|
|
|
|
K V S Chand wrote: populate this column onto datagrid,
What does that mean? Are you using DataBinding?
led mike
|
|
|
|
|
Column means a column in XML.
Yah, I am binding XML data to a DataGrid using dataset.
Thank u
Chandu
|
|
|
|
|
K V S Chand wrote: Column means a column in XML.
There is no such thing as a "column" in XML. If you plan on using text based communications for solving your programming problems don't you think it might be a good idea to learn and use the standard terms for a given technology? Otherwise how do expect to be able to communicate. XML has nodes and elements and attributes, no columns, so I have no idea what you are talking about.
led mike
|
|
|
|
|
i created an xml file using xml serialization for a c# CLASS.
BUT I GOT ALL THE FIELDS FROM THAT CLASS. HOW CAN I REMOVE UN NECESSARY ATTRIBUTES.
CAN ANYBODY HELP ME PLEASE?
KSRS
|
|
|
|
|
First, please don't shout.
Second if it is class that you have created simply apply the [System.Xml.Serialization.XmlIgnoreAttribute] to the properties that you don't want to show.
If it is a framework class, you need to get the data from the XMLSerializer object to an XML document object for manipulation. If this is the case and you have problems with this, please post the specifics.
topcoderjax - Remember, Google is your friend.
|
|
|
|
|
hi iam new to the Xpath
could anyone help me?? i just want to pick up countryname which is element and it has a attribute for the code. i want to pick these values from the XmlDoc
the code here as follows:-
Dim CountryPropExpr As XPath.XPathExpression = Nav.Compile("./CountryName[@Code=""]")
Dim CountryPropIter As XPath.XPathNodeIterator = Nav.Select(CountryPropExpr)
If CountryPropIter IsNot Nothing AndAlso CountryPropIter.Count > 0 Then
Try
Dim CountryNameCode As String = getNodeValue(CountryPropIter.Current.SelectSingleNode("./CountryName[@Code=""]"))
For Each CountryNameCode In CountryPropIter
CountryNameCode = CountryPropIter.Current.Value
Next
Builder.AppendLine("<countryname code="" ""="">")
Catch ex As Exception
Debug.Write(ex.Message)
End Try
End If
when i compile it didn't pickup the values.
Thanks Heaps in Advance
|
|
|
|
|
Please provide a document fragment. Without the XML, there is noway to test the validity of your method call.
"In quiet and silence, the truth is made clear."
|
|
|
|
|
Could someone advise me on the syntax to use to get the IXMLNode whose attribute id="abc" so in the XPath expression used to SelectSinglenode you would specifiy the @id="abc" or whatever the correct syntax is so as to select the Node whose attribute id has the value == "abc".
Thanks.
|
|
|
|
|
Basically, I want to locate and return any Node in the XML document which has an attribute id equal to the id I am searching for.
I have been trying with XPath's such as:
"//*[@id( 'abc' )]"
But alas so far I have not found the correct syntax.
|
|
|
|