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

XPath data model and the XML Declaration

Hi

Compontents of an xml file are mapped to the different node types of the
xpath data model.
An element is mapped to an element node, an attribute node represents an
attribute and its value ... and so on.

so far so good

But what happens to the xml declaration (<?xml version="1.0" ......?>).
Though it looks like a processing instruction it isn't.

The XPath specification [1] only says that the XML Declaration does not map
to a the node type processing instruction node (5.5).

Does the XML Declaration map to a Xpath node type or not.
If yes - what type of node?

thx

Helmut
[1] XPath Specification http://www.w3c.org/TR/xpath
Jul 20 '05 #1
4 3571

Does the XML Declaration map to a Xpath node type or not.
If yes - what type of node?

No, it affects the parser (eg telling it what encoding has been used),
and so affects the construction of the node tree, but no record of the
declaration is left in the node set.

That's (normally) what you want. If you have a file in latin1 that
starts
<?xml version="1.0" encoding="iso-8859-1"?>
...

and the same data encoded in utf-8 that starts

<?xml version="1.0" encoding="utf-8"?>

Then you want these two to be equivalent. The actual data in the nodes
are just logical unicode characters, the encoding used to store them
originally in a file shouldn't be relevant to the logical view of the
XML tree (and isn't available to XPath/XSLT).

Of course in many cases it's not unrreasonable to want to output a file
with the same encoding as was used for input, but that information has
gone, along with information about whether " or ' was used for
attributes, or where CDATA sections were, etc.

David
Jul 20 '05 #2
* Helmut Dirtinger wrote in comp.text.xml:
Does the XML Declaration map to a Xpath node type or not.


No, it does not. The XML declaration does not contain information that
would make sense to be available in the data model.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jul 20 '05 #3
In article <41****************@news.bjoern.hoehrmann.de>,
Bjoern Hoehrmann <bj****@hoehrmann.de> wrote:
Does the XML Declaration map to a Xpath node type or not.
No, it does not.


True.
The XML declaration does not contain information that
would make sense to be available in the data model.


But this is an exaggeration. The encoding is a useful hint when
serializing the data model, and the XML version number affects what
assumptions you can make about the data (e.g. whether it might have
C0 control characters in it).

-- Richard

Jul 20 '05 #4
* Richard Tobin wrote in comp.text.xml:
The XML declaration does not contain information that
would make sense to be available in the data model.


But this is an exaggeration. The encoding is a useful hint when
serializing the data model, and the XML version number affects what
assumptions you can make about the data (e.g. whether it might have
C0 control characters in it).


The problem is however that the value of the encoding pseudo-attribute
might not be the actual character encoding of the document, for example
if the document is delivered via HTTP the acutal encoding might be
specified in the HTTP header which would then override the value in the
XML declaration (if any). So it would make more sense to use other means
to get that information, for example using DOM Level 3 Core methods.

Regarding C0 control characters, I do not think these may appear in the
XPath 1.0 data model which is only defined for XML 1.0 (they are not
allowed to appear in expressions either, strings are restricted to chars
as defined in XML 1.0 which excludes C0 controls)... and if they are in
the data model, you can infer that the XML version is 1.1 so this is of
limited use, too.

Other uses would be possible too, for example, if you want to write an
XSLT document that discovers meta-data from XML documents like

XML Declaration: yes
Encoding Declaration: ISO-8859-1
Standalone: no

Elements:

1 <html>
1 <head>
1 <body>
32 <div>
...

or whatever, so maybe I should rephrase to, the value such functionality
would add is not considered worth the additional complication and such
functionality might contribute to making false assumptions such as that
the encoding in the XML declaration is the actual document encoding.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jul 20 '05 #5

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

Similar topics

1
by: Fede | last post by:
Hi to all! How can I replace a DocumentType Declaration in a XML file using XMLDocument and XPath? Thanks in advance. Fede.
12
by: Lawrence Oluyede | last post by:
I've some problems with filtering out a specific element by the following xml snippet (is part of a bigger xml document): <entry> <link...
3
by: Stefan Behnel | last post by:
Hi! I need to generate source code (mainly Java) from a domain specific XML language, preferably from within a Python environment (since that's where the XML is generated). I tried using...
15
by: aidy | last post by:
Hi, Is it possible to retrieve CDATA Sections from an XML document? If so, could someone give me a syntax example? Cheers Aidy
2
by: Lonewolf | last post by:
Hi all, please pardon me if this question is too trivial. I have an XML file which stores data in base64. The schema is something like this, <Remokon> <Brand Name="SONY"> <Model Name="Type 1",...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
6
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot...
2
by: =?Utf-8?B?T2xpdmllcjc3Nzc=?= | last post by:
Hi, I have an issue displaying data with the treeview control. Here is my xml file : <ROOT> <FOLDER> <MODEL> <REPORT>
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.