|
Never mind, I figured out how to work around this which was an easier solution.
Jason W.
|
|
|
|
|
I can not read a XML file with or without a scheme using XMLDocument.LoadXML() without getting an exception.
Thanks for your suggestions.
Given this XML file name 'simple1.xml'
<?xml version="1.0" encoding="utf-8" ?>
<book>
<title> my books title</title>
</book>
I had hoped to read it in with this code.
string pathfilename = @"C:\XML_Class\Example\ReadWriteFamily\simple1.xml";
try
{
XmlNode currNode;
XmlDocument doc = new XmlDocument();
//The LoadXml statement throws this exception
//"System.Xml.XmlException: The data at the root level is invalid.
//Line 1, position 1.\r\n at System.Xml.XmlTextReader.ParseRoot()\r\n
//at System.Xml.XmlTextReader.Read()\r\n at System.Xml.XmlValidatingReader.ReadWithCollectTextToken()\r\n
//at System.Xml.XmlValidatingReader.Read()\r\n at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)\r\n
//at System.Xml.XmlDocument.Load(XmlReader reader)\r\n at System.Xml.XmlDocument.LoadXml(String xml)\r\n
//at ReadWriteFamily.Form1.ReadSimple1_Click(Object sender, EventArgs e)
//in c:\\xml_class\\example\\readwritefamily\\form1.cs:line 236" string
doc.LoadXml(pathfilename); //exception throw here
XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
docFrag.InnerXml="<title>inserted title</title>" ;
// insert the availability node into the document
currNode = doc.DocumentElement.FirstChild;
currNode.InsertAfter(docFrag, currNode.LastChild);
//save the output to a file
//doc.Save(pathfilename2);
}
catch (Exception eException)
{
string s =eException.ToString();
Console.WriteLine ("Exception: {0}", s);
}
}
}
|
|
|
|
|
method LoadXml() method takes as parameter actual markup, not filename. That's why it throws exception, cuz "C:\XML_Class\Example\ReadWriteFamily\simple1.xml" is definitely not a valid well-formed XML markup Use Load() method instead.
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
|
I have a project that uses a style sheat to transform data. I want to save the result into DB to use at a later time. When I convert the stream to a string, or attempt to load it back into a dom doc, it fails.
Code: C# -- Out ms is memory stream
xslt.Transform(XmlDoc, null, OutMS, null);
returnXML = System.Text.Encoding.Default.GetString(OutMS.ToArray());
I have tried every type of encoding. utf 8, 16 etc...
Unprintable characters on the front of every one.
Thanks T. J.
|
|
|
|
|
well I don't have experiences with this, bt you could take a look at XmlResolver as I suspect you need to provide it in order to deal with entites - and I *think* (read I have no idea) XSLT could encode some unprintable characters - since whitespace is normaly not an issue as XML processors ignore it.
I also remeber guy who had problem with encoding (XML in string) and I think he solved it with String.Replace(). Try search forum...
I am not sure, I may say BS so plz correct me if I am wrong...
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Found the solution Thanks anyway. Here it is if anyone wants to know.
There is a stringwriter object based on textwriter that will work. here is the code.
StringWriter writer = new StringWriter();
////////////////////////////////////////
// Load Template into Transformer and //
// Transform the XML that came in //
////////////////////////////////////////
xslt.Transform(XmlDoc.CreateNavigator(), null, writer, null);
returnXML = writer.ToString();
Thanks T. J.
|
|
|
|
|
I am trying to write a schema to validate an xml file. I can get it to validate everything correctly. I have one problem though. In the xml file, after a certain element, I am not going to know what will be there.
ex.
<Node1>
<Node2>
<Node3>
//After this point, the layout could change at any time (and without notice I might add)
//and I don't want to have to keep changing the schema everytime the layout changes.
</Node3>
</Node2>
</Node1>
Anyways, my question is, how would I write the schema to stop the validation at that point? Thanks.
|
|
|
|
|
hi,
<xs:any> should do the job.
W3C XML Schema spec.[^]
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
When I change it I get this exception "The 'http://www.w3.org/2001/XMLSchema:any' element is not supported in this context". Any advice.
|
|
|
|
|
Nevermind, I changed it to
<xs:complexType name="Node4">
<xs:sequence>
<xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="skip" />
<xs:sequence>
<xs:complexType>
<xs:element name="Node4" type="Node4" minOccurs="0" maxOccurs="1" />
Maybe not that exactly, but it worked. Thanks for the help
|
|
|
|
|
I have been teaching myself XML for a short time noe, and I want to move into using it with JavaScript for web sites. However, I would like to avoid using the typical "new ActiveXObject(Microsoft.XMLDOM)" line. Is there an alternative to ActiveX/Microsoft?
|
|
|
|
|
|
:->:->:->
|
|
|
|
|
I'm new to XML and today a guy asked me how to get to a particular node in a very big XML file(1-2 Gigs).
Do you guys have any ideas?
Thanks so much.
|
|
|
|
|
Anonymous wrote:
very big XML file(1-2 Gigs)
That's not good...
Well first (obvious) idea is not to read whole XML document to memory - XmlDocument . I'd maybe use XmlTextReader , bt I am not sure how to get particular node - is it described with XPath or ...how?
Anonymous wrote:
I'm new to XML
hmm in case you don't know XPath, XmlDocument, XmlTextReader etc. feel free to ask - or google
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi, i want to display info from 2 tables [users] and [friends]. there are a relations between users.id and friends.iduser. when i display i only can display the info from the table [users].
Anyone could help me on displaying info from relations tables? any has a little example plz?
|
|
|
|
|
hmmm, that looks like SQL problem... how does it go with XML/XSL?
Anyway, if it is SQL, you can do something like
SELECT users.name, friends.idontknowhat FROM users, friends WHERE users.id = friends.iduser
or is it in XML?
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
i have declared two XML objects the first has as datasrc=select * from users and the 2 has select * from users where iduser=@iduser, the problem that i have is that i dont know how to pass the second variable , the iduser from the first xml object, is this posible??
any sugerencies?
thanks
|
|
|
|
|
Can anyone give me a detailed explaination about when to use CSS and XSLFO?
What are the advantages between them. Which is more efficient interms of
maintence.
|
|
|
|
|
|
|
My question is can we serialize an array (array of objects) at a time in .Net. Can anybody annswer me........
Thanx
Pradosh
|
|
|
|
|
Did you try?
As quick look at MSDN shows it (System.Array ) has [Serializable] attribute, so I guess answer is YES.
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Here's my code:
try
{
_strContent = "<Employees><Employee id=\"1\"><Name>Ethan</Name></Employee></Employees>"
_xmlDoc.Load(".\\EMP.xml");
_docFrag = _xmlDoc.CreateDocumentFragment();
_docFrag.InnerXml = _strContent;
_xmlDoc.DocumentElement.AppendChild(_docFrag);
_xmlDoc.Save(".\\EMP.xml");
}
catch(Exception exc)
{
MessageBox.Show(exc.ToString());
}
The EMP.xml is already existing. I just used the above block of code to add new nodes into an existing EMP.xml file. But, I received this exception:
This is an unexpected token. The expected token is 'EndElement'
Unlikely though, the code performs its function. When I check the file, I saw that the node I am trying to add was there, its just that the error keeps on prompting. Will anyone help me? Thanks in advance!
----------------------
Seeing the infinite...
|
|
|
|