|
Hi, I am trying to use XPath in my VC++.NET application to navigate my XML document. But I am getting nothing when I run <code>Select()</code> method of <code>XPathNavigator</code> class. I am posting my XML, XSD and CODE with this message. Can I know what is the problem with this code?
XSD File:
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:target="http://www.example.com/name" targetNamespace="http://www.example.com/name" elementFormDefault="qualified">
<element name="name">
<complexType>
<sequence>
<element name="first" type="string"/>
<element name="middle" type="string"/>
<element name="last" type="string"/>
</sequence>
<attribute name="title" type="string"/>
</complexType>
</element>
</schema>
XML File:
<?xml version="1.0"?>
<name xmlns="http://www.example.com/name" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/name name5.xsd" title="Mr.">
<first>John</first>
<middle>Fitzgerald Johansen</middle>
<last>Doe</last>
</name>
VC++.NET code:
XmlDocument* m_myDoc = new XmlDocument();
m_myDoc->Load(S"name5.xml");
XPathNavigator* m_myNav = m_myDoc->CreateNavigator();
m_myNav->MoveToRoot();
XPathNodeIterator* myNodeIte = m_myNav->Select(S"/name");
int cnt = myNodeIte->Count;
I am getting no data from this doce.
Thanks in advance.
Priyank
|
|
|
|
|
The problem is that the name element you're trying to select is in the "http://www.example.com/name" namespace (via xmlns attribute) but your XPath expression looks for a name element in the empty namespace. Use the overload of Select that takes an additional IXmlNamespaceResolver instance. The example of the MSDN topic should give you an idea on how to adjust your code.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi
In side my ASPPage I am creating XMLDomDcoument and HTTPRequest Object . I have listed here the Code
Processing flow
1. Loading XML Content from Request Object to XMLDOMDocument
2. Opening our DataCenter Server’s ASP Page by MSXML2.XMLHTTP Object
3. Sending the XMLDOMDocument by MSXML2.XMLHTTP object
<!--#include file="dataCenter.asp"--><br />
<% Set objXMLDocument = CreateObject("MSXML2.DOMDocument")<br />
dataCenter=dataCenter & Mid(Request.ServerVariables("URL"), InStrRev(Request.ServerVariables("URL"), "/")+1) & "?rt=GWAY"<br />
Set objHTTPRequest = CreateObject("MSXML2.XMLHTTP")<br />
objXMLDocument.load(Request)<br />
objHTTPRequest.open "POST", dataCenter, False <br />
objHTTPRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"<br />
objHTTPRequest.send objXMLDocument<br />
ret = objHTTPRequest.responseText<br />
Response.Write ret<br />
Set objXMLDocument = Nothing<br />
Set objHTTPRequest = Nothing<br />
%>
Everything working fine for some time (likely1 hour or 55 minutes ) After that , My Script engine is throwing a Error like
“ Failed to Create Object CreateObject("MSXML2.DOMDocument") “
After restarting my webserice, it working fine and come to same status as mention above
I have question on this issue
1. Whether it is VBScript Engine Issue
2. Whether it is MSXML2.DOMDocument Issue
Thanks in advance
g.p.swamy
|
|
|
|
|
hi friends
how to create the bar chart from xml dynamically in asp.net
thanx
regards
saravanan
|
|
|
|
|
and your problem is exactly ... ?
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
I"m relatively new to XML and I have to create a schema for our company.
I"m a little confused as to the best practices for creating a schema, particularly, what should be an attribute versus a child element.
I also dont know if its best to use global elements and reuse them as child elements or to use a global complexType. Any best practices for this?
The final goal is to create an interface that reads and processes XML, but we're starting w/ our schema definition.
Is it easier programatically to read attributes vs elements using MSXML? Any ideas? Good books on C# and XML?
Thanks.
-C
|
|
|
|
|
Wheatbread wrote: I"m a little confused as to the best practices for creating a schema, particularly, what should be an attribute versus a child element.
Overusage of elements tend to bloat your XML document. I primarily view an element as a hierarchical container of nodes.
Attributes tend to flatten the hierarchy and make your document smaller. I mostly use attributes to uniquely identify and describe an element. However, attributes cannot contain other nodes except for a text node.
How you use elements and attributes is dependent on the data you are trying to represent.
Wheatbread wrote: I also dont know if its best to use global elements and reuse them as child elements or to use a global complexType. Any best practices for this?
You should be aware that a globally defined element can be used as the root element. More than one globally defined element allows a list of roots to choose from. To enforce only one choice of a root element, you must only define one globally and nest all other element declarations into complex type definitions.
Wheatbread wrote: Is it easier programatically to read attributes vs elements using MSXML?
Attributes might be a little easier. Once you have selected an element, the attributes are in name/value pair container off the selected element object.
Wheatbread wrote: Good books on C# and XML?
I cannot really list any books on learning C# or XML since I am not familiar with your background and preferences. I tend to buy reference type books. However, I will list a few web sites that can get you started:
http://www.informit.com/guides/index.asp?rl=1[^]
http://www.w3schools.com/[^]
http://www.topxml.com/[^]
http://www.xml.com/[^]
|
|
|
|
|
Just a few more questions:
So, if I have info that's from a database, probably makes more sense to have elements for a 1:1 relationship w/ the fields of a given record?
My data model is used for communication, serial or network. I have alot of data/value pairs. So I used attributes to describe the value, instead of making alot of elements. For readability, its easier as well. There's a possibility that the data points may be entered into a database, so if I use an XSLT later that I wont have issues w/ linking an attribute to a database field.
I understand the one global element piece, so I removed the other globals elements. I just noticed that an example from another corporate XML communication XSD had multiple globals, and I"m just to figure if I need them.
Thanks again.
-C
|
|
|
|
|
Wheatbread wrote: So, if I have info that's from a database, probably makes more sense to have elements for a 1:1 relationship w/ the fields of a given record?
My data model is used for communication, serial or network. I have alot of data/value pairs. So I used attributes to describe the value, instead of making alot of elements. For readability, its easier as well. There's a possibility that the data points may be entered into a database, so if I use an XSLT later that I wont have issues w/ linking an attribute to a database field.
The usage of elements vs attributes is very subjective. It can be influence by the source and the usage of the output. You can also mix the two together. If you need to change the format of your XML document to meet someone else's needs, you can always transform it via XSLT.
George
|
|
|
|
|
Wheatbread wrote: what should be an attribute versus a child element.
I dont really know what best practices for this are, this is my opinion
Use attributes for what you treat as atomic data, elements for everything that has structure.
Let me explain what I mean when I write "what you treat as..". For example: you have some element representing same thing as record in database, and it has "last modified" attribute. You can view date as NOT atomic. It has attributes "year", "month" etc. You should then have element "last modified" with those attributes, shouldn't you? BUT most probably you use that "last modified" information kind of atomicaly, you always assign\read DateTime object in your code, right. In DB, you have one column of Date type, not columns lastmodifiedday, lastmodifiedmonth, lastmodifiedyear.. Its one value after all. Think of it as number of ticks since 1900 represented as string in dd-mm-yyyy format. Or so.
Umm, now I dunno if my "explanation" did make it clearer
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
I'm not sure I'm following your explanation. My data model is for communication (serial or network), so we matching a database definition isnt as important. But there's a good chance data will eventually be mapped to a database table. So I want to make sure that when we do have to write to a DB that the data model is designed correctly and not complicate things.
-C
|
|
|
|
|
Wheatbread wrote: I'm not sure I'm following your explanation.
No surprise here, I have some difficulties explaining this.
What I was trying to say is that
<file lastModified="22\8\2006" name="file.txt" size="10" />
is ok but
<file name="file.txt" size="10" >
<lastModified>
<day value="22" />
<month value="8" />
<year value="2006" />
</lastModified>
</file>
is probably bad. You can say that day\month\year is VALUE of date, but you cant say it CONTAINS day and month and year, IMO
But
<computer name="myPC">
<disc name="c" >
<folder name="texts">
<file name="text.txt">
</folder>
<folder name="pics">
<file name="image.jpg">
</folder>
<disc name="d" />
</computer>
is better then
<computer name="myPC">
<disc name="c" >
<folder name="texts" files="text.txt;text2.txt" />
<folder name="pics" files="image.jpg;picture.gif" />
<disc name="d" />
</computer>
because when you want to do
<computer name="myPC">
<disc name="c" >
<folder name="texts">
<file name="text.txt" lastModified="8/7/2004">
</folder>
<folder name="pics">
<file name="image.jpg" lastModified="4/3/2006">
</folder>
<disc name="d" />
</computer>
you are screwed in second scenario, because you expected folders to be atomic (csv list of files describes folder) but they suddenly aren't. As in my example with date, if you say VALUE of folder is list of its files (which is retarded idea but its only example of bad practice; best I could think of ) you get the first scenario, but if you realize that folder CONTAINS files you get the second one.
And if there is some flaw in my thinking let me know guys.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Hi,
As per the three module of development (related to data access from SQL to the front -end and reports on Html)i have developed (ASP.net With c#) n tested it. Its running ok. Speed is also fine as compare to Crystal Report.
Sincearly i have no idea about how the data(format)comes from SQL to the main application.
Is there any better solution,for data transfer in XML . if there is then plzz kindly reply me..
sincerly,
Shriya
|
|
|
|
|
Hi,
I am not very much sure about what your question is.
Do you need to get the data from the database in XML format. Then if you are using Sql Server, try to use FOR XML inn select sql.
Alternatively you can fill data into a dataset and then use that dataset to create a XmlDataDocument. Then if you are using XSLT for your report, then you can make use of the XmlDataDocument.
Pradipta Basu
|
|
|
|
|
Element Nodes in XML file have attributes associated with them.
I randomly select element nodes in an XML document after loading it using DOM class. The selected element node can have zero or more Attributes associated with it.
If selected xml node got attribute I displayed it in ListView.
Attribute Name: Being First ColumnHeader
Attribute Value: Being Second ColumnHeader
Name Item being label of listView can be edited if i enable "labeledit" in property of listView.
But Value under the subitem cannot be edited.
1. How can i simply edit both field using listView?
2. Is there any other control or method that will help me create 2 columns according to number of attributes and enable me to edit fields?
3. How can I edit listBox items? Is there any possibility of using it.
Your reply will be highly appreciated.
Thank you.
Language: Visual C#
|
|
|
|
|
please help me to get some good examples of .xsd file. i need to taks a seminar about this
thankyou
yesuprakash
|
|
|
|
|
Ask google or the search engine of your choice and you will get many answers.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
XPath: /APP/INCOME[@USERID='25']/@Amount
|
|
|
|
|
how to avoid showing coifirm dialog box after editing the xml file through program.
thankyou
Yesuprakash
|
|
|
|
|
ypki wrote: how to avoid showing coifirm dialog box after editing the xml file through program.
Which program are you talking about?
|
|
|
|
|
ctrl-s
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Here's a fun little app written in C# using .NET Frameworks 2.0.
See: XML Notepad 2007.
Handy features include:
- Tree View synchronized with Node Text View for quick editing of node names and values.
- Incremental search (Ctrl+I) in both tree and text views, so as you type it navigates to matching nodes.
- Cut/copy/paste with full namespace support.
- Drag/drop support for easy manipulation of the tree, even across different instances of XML Notepad and from the file system.
- Infinite undo/redo for all edit operations.
- In place popup multi-line editing of large text node values.
- Configurable fonts and colors via the options dialog.
- Full find/replace dialog with support for regex and XPath.
- Good performance on large XML documents, loading a 3mb document in about one second.
- Instant XML schema validation while you edit with errors and warnings shown in the task list window.
- Intellisense based on expected elements and attributes and enumerated simple type values.
- Support for custom editors for date, dateTime and time datatypes and other types like color.
- Handy nudge tool bar buttons for quick movement of nodes up and down the tree.
- Inplace HTML viewer for processing xml-stylesheet processing instructions.
- Built-in XML Diff tool.
Enjoy!
Chris Lovett
|
|
|
|
|
In XML Notepad 2007 after loading XML file. If I right click on the attribute in treeView I can add Element "Before" or "After" that attribute node. I don't understand why there is need for this functionality. If we click "Before" on popup menu in elementItem, it adds node under the selected attribute node. If I click on After it adds node under the previously added node.
|
|
|
|
|
HI,
Can anyone tell me how to find whether a tag in Xml file is repeated...(i.e)duplicated.can this be done thru VB.NET coding....
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<h1> Time Table</h1>
<xsl:for-each select="TimeTable/Lecture">
<tr>
<td> <xsl:value-of select="CourseTitle"/></td>
<td> <xsl:value-of select="Lecturer"/></td>
<td> <xsl:value-of select="Room"/></td>
<td> <xsl:value-of select="Time"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This code display the time table . Now I have to apply a check over it.
CHECK: At one time (Time) there would be only one lecture (CourseTitle) in a room, If there are multilple, it should display a message of CLASH.
Can any one tell me how I can embed this logic in XSL sheet?
|
|
|
|