Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Can I use ../@mp:localname?

 
   Database Help (Home) -> XML RSS
Next:  Complex Query Question  
Author Message
Julie

External


Since: Aug 11, 2008
Posts: 8



(Msg. 1) Posted: Wed Nov 12, 2008 2:11 pm
Post subject: Can I use ../@mp:localname?
Archived from groups: microsoft>public>sqlserver>xml (more info?)

Hi,

I need to get the name of the parent node and used "../@mp:localname" in the
openxml statement. I got an error when trying to execute the query:

XML parsing error: Reference to undeclared namespace prefix: 'mp'

However, the query execute just fine if I use @mp:localname. It seems that I
cannot use the xpath expression like "/" or "..". However, I do see some
people using it on some online articles. I wonder whether there are any
server settings that need to be changed. I am using SQL Server 2005.

Thanks for any suggestions!

Julie

 >> Stay informed about: Can I use ../@mp:localname? 
Back to top
Login to vote
Bob

External


Since: Feb 08, 2005
Posts: 182



(Msg. 2) Posted: Wed Nov 12, 2008 3:12 pm
Post subject: RE: Can I use ../@mp:localname? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Could you post some sample XML and the SQL you are running? There's no
reason you can't do something like this with the local-name(.) function. Is
that what you mean?

DECLARE @xml XML

SET @xml = '<root>
<Person>Julie</Person>
<Person>wBob</Person>
</root>'

SELECT
x.y.value('local-name(.)', 'VARCHAR(50)'),
x.y.value('.', 'VARCHAR(50)')
FROM @xml.nodes('//*') AS x(y)

"Julie" wrote:

> Hi,
>
> I need to get the name of the parent node and used "../@mp:localname" in the
> openxml statement. I got an error when trying to execute the query:
>
> XML parsing error: Reference to undeclared namespace prefix: 'mp'
>
> However, the query execute just fine if I use @mp:localname. It seems that I
> cannot use the xpath expression like "/" or "..". However, I do see some
> people using it on some online articles. I wonder whether there are any
> server settings that need to be changed. I am using SQL Server 2005.
>
> Thanks for any suggestions!
>
> Julie

 >> Stay informed about: Can I use ../@mp:localname? 
Back to top
Login to vote
Julie

External


Since: Aug 11, 2008
Posts: 8



(Msg. 3) Posted: Thu Nov 13, 2008 9:57 am
Post subject: RE: Can I use ../@mp:localname? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank you Bob. I can use ".", "/", etc. xpath expressions with my xml but I
cannot use these expressions with @mp:localname or other syntax that retrieve
meta data of the XML. An example could be:

declare @xml XML, @idoc int

set @xml='<controlledVocabulary>
<category databaseId="AWB_CV" thesaurusId="6">
<cachedCategoryInformation date="2007-08-06T16:03:49-04:00">
<categoryName>Subject</categoryName>
</cachedCategoryInformation>
<validatedTerm termId="1667">
<cachedTermInformation date="2008-10-31T11:48:13-04:00">
<termName>Accounting standards</termName>
<authority>Collins Dictionary of Business</authority>
</cachedTermInformation>
</validatedTerm>
</category>
</controlledVocabulary>'

EXEC sp_xml_preparedocument @idoc OUTPUT, @xml
select * from openxml (@idoc, '//validatedTerm', 2)
with (Term nvarchar(500) 'cachedTermInformation/termName',
TermID bigint './@termId',
NodeID nvarchar(100) '../../../@id',
NodeType varchar(50) '@mp:localname')

Works fine and I got:
TermID NodeID Term NodeType
1667 NULL Accounting standards validatedTerm

However, if I change the last line of the code to:
NodeType varchar(50) '../../@mp:localname')

I got error:

Msg 6603, Level 16, State 2, Line 21
XML parsing error: Reference to undeclared namespace prefix: 'mp'.

The namespace "mp" is no longer recognized.

Thanks for your help.

Jie
"Bob" wrote:

> Could you post some sample XML and the SQL you are running? There's no
> reason you can't do something like this with the local-name(.) function. Is
> that what you mean?
>
> DECLARE @xml XML
>
> SET @xml = '<root>
> <Person>Julie</Person>
> <Person>wBob</Person>
> </root>'
>
> SELECT
> x.y.value('local-name(.)', 'VARCHAR(50)'),
> x.y.value('.', 'VARCHAR(50)')
> FROM @xml.nodes('//*') AS x(y)
>
> "Julie" wrote:
>
> > Hi,
> >
> > I need to get the name of the parent node and used "../@mp:localname" in the
> > openxml statement. I got an error when trying to execute the query:
> >
> > XML parsing error: Reference to undeclared namespace prefix: 'mp'
> >
> > However, the query execute just fine if I use @mp:localname. It seems that I
> > cannot use the xpath expression like "/" or "..". However, I do see some
> > people using it on some online articles. I wonder whether there are any
> > server settings that need to be changed. I am using SQL Server 2005.
> >
> > Thanks for any suggestions!
> >
> > Julie
 >> Stay informed about: Can I use ../@mp:localname? 
Back to top
Login to vote
Bob

External


Since: Feb 08, 2005
Posts: 182



(Msg. 4) Posted: Thu Nov 13, 2008 3:38 pm
Post subject: RE: Can I use ../@mp:localname? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hmm, not sure about that syntax. In SQL 2005 you can use XQuery to query
XML, although I'm not entirely sure what your expected results are:

SELECT
x.y.value('(cachedTermInformation/termName)[1]', 'VARCHAR(MAX)' ) AS Term,
x.y.value('@termId', 'BIGINT' ) AS TermId,
'???' AS NodeId,
x.y.value('local-name(.)', 'VARCHAR(MAX)' ) AS NodeType
FROM @xml.nodes('controlledVocabulary/category/validatedTerm') x(y)



"Julie" wrote:

> Thank you Bob. I can use ".", "/", etc. xpath expressions with my xml but I
> cannot use these expressions with @mp:localname or other syntax that retrieve
> meta data of the XML. An example could be:
>
> declare @xml XML, @idoc int
>
> set @xml='<controlledVocabulary>
> <category databaseId="AWB_CV" thesaurusId="6">
> <cachedCategoryInformation date="2007-08-06T16:03:49-04:00">
> <categoryName>Subject</categoryName>
> </cachedCategoryInformation>
> <validatedTerm termId="1667">
> <cachedTermInformation date="2008-10-31T11:48:13-04:00">
> <termName>Accounting standards</termName>
> <authority>Collins Dictionary of Business</authority>
> </cachedTermInformation>
> </validatedTerm>
> </category>
> </controlledVocabulary>'
>
> EXEC sp_xml_preparedocument @idoc OUTPUT, @xml
> select * from openxml (@idoc, '//validatedTerm', 2)
> with (Term nvarchar(500) 'cachedTermInformation/termName',
> TermID bigint './@termId',
> NodeID nvarchar(100) '../../../@id',
> NodeType varchar(50) '@mp:localname')
>
> Works fine and I got:
> TermID NodeID Term NodeType
> 1667 NULL Accounting standards validatedTerm
>
> However, if I change the last line of the code to:
> NodeType varchar(50) '../../@mp:localname')
>
> I got error:
>
> Msg 6603, Level 16, State 2, Line 21
> XML parsing error: Reference to undeclared namespace prefix: 'mp'.
>
> The namespace "mp" is no longer recognized.
>
> Thanks for your help.
>
> Jie
> "Bob" wrote:
>
> > Could you post some sample XML and the SQL you are running? There's no
> > reason you can't do something like this with the local-name(.) function. Is
> > that what you mean?
> >
> > DECLARE @xml XML
> >
> > SET @xml = '<root>
> > <Person>Julie</Person>
> > <Person>wBob</Person>
> > </root>'
> >
> > SELECT
> > x.y.value('local-name(.)', 'VARCHAR(50)'),
> > x.y.value('.', 'VARCHAR(50)')
> > FROM @xml.nodes('//*') AS x(y)
> >
> > "Julie" wrote:
> >
> > > Hi,
> > >
> > > I need to get the name of the parent node and used "../@mp:localname" in the
> > > openxml statement. I got an error when trying to execute the query:
> > >
> > > XML parsing error: Reference to undeclared namespace prefix: 'mp'
> > >
> > > However, the query execute just fine if I use @mp:localname. It seems that I
> > > cannot use the xpath expression like "/" or "..". However, I do see some
> > > people using it on some online articles. I wonder whether there are any
> > > server settings that need to be changed. I am using SQL Server 2005.
> > >
> > > Thanks for any suggestions!
> > >
> > > Julie
 >> Stay informed about: Can I use ../@mp:localname? 
Back to top
Login to vote
Julie

External


Since: Aug 11, 2008
Posts: 8



(Msg. 5) Posted: Thu Nov 20, 2008 11:12 am
Post subject: RE: Can I use ../@mp:localname? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank you Bob. I basically want to get the metadata of the xml nodes, i.e. I
want to know what is the name of a particular node. I'll try XQuery and see
whether it is helpful.

"Bob" wrote:

> Hmm, not sure about that syntax. In SQL 2005 you can use XQuery to query
> XML, although I'm not entirely sure what your expected results are:
>
> SELECT
> x.y.value('(cachedTermInformation/termName)[1]', 'VARCHAR(MAX)' ) AS Term,
> x.y.value('@termId', 'BIGINT' ) AS TermId,
> '???' AS NodeId,
> x.y.value('local-name(.)', 'VARCHAR(MAX)' ) AS NodeType
> FROM @xml.nodes('controlledVocabulary/category/validatedTerm') x(y)
>
>
>
> "Julie" wrote:
>
> > Thank you Bob. I can use ".", "/", etc. xpath expressions with my xml but I
> > cannot use these expressions with @mp:localname or other syntax that retrieve
> > meta data of the XML. An example could be:
> >
> > declare @xml XML, @idoc int
> >
> > set @xml='<controlledVocabulary>
> > <category databaseId="AWB_CV" thesaurusId="6">
> > <cachedCategoryInformation date="2007-08-06T16:03:49-04:00">
> > <categoryName>Subject</categoryName>
> > </cachedCategoryInformation>
> > <validatedTerm termId="1667">
> > <cachedTermInformation date="2008-10-31T11:48:13-04:00">
> > <termName>Accounting standards</termName>
> > <authority>Collins Dictionary of Business</authority>
> > </cachedTermInformation>
> > </validatedTerm>
> > </category>
> > </controlledVocabulary>'
> >
> > EXEC sp_xml_preparedocument @idoc OUTPUT, @xml
> > select * from openxml (@idoc, '//validatedTerm', 2)
> > with (Term nvarchar(500) 'cachedTermInformation/termName',
> > TermID bigint './@termId',
> > NodeID nvarchar(100) '../../../@id',
> > NodeType varchar(50) '@mp:localname')
> >
> > Works fine and I got:
> > TermID NodeID Term NodeType
> > 1667 NULL Accounting standards validatedTerm
> >
> > However, if I change the last line of the code to:
> > NodeType varchar(50) '../../@mp:localname')
> >
> > I got error:
> >
> > Msg 6603, Level 16, State 2, Line 21
> > XML parsing error: Reference to undeclared namespace prefix: 'mp'.
> >
> > The namespace "mp" is no longer recognized.
> >
> > Thanks for your help.
> >
> > Jie
> > "Bob" wrote:
> >
> > > Could you post some sample XML and the SQL you are running? There's no
> > > reason you can't do something like this with the local-name(.) function. Is
> > > that what you mean?
> > >
> > > DECLARE @xml XML
> > >
> > > SET @xml = '<root>
> > > <Person>Julie</Person>
> > > <Person>wBob</Person>
> > > </root>'
> > >
> > > SELECT
> > > x.y.value('local-name(.)', 'VARCHAR(50)'),
> > > x.y.value('.', 'VARCHAR(50)')
> > > FROM @xml.nodes('//*') AS x(y)
> > >
> > > "Julie" wrote:
> > >
> > > > Hi,
> > > >
> > > > I need to get the name of the parent node and used "../@mp:localname" in the
> > > > openxml statement. I got an error when trying to execute the query:
> > > >
> > > > XML parsing error: Reference to undeclared namespace prefix: 'mp'
> > > >
> > > > However, the query execute just fine if I use @mp:localname. It seems that I
> > > > cannot use the xpath expression like "/" or "..". However, I do see some
> > > > people using it on some online articles. I wonder whether there are any
> > > > server settings that need to be changed. I am using SQL Server 2005.
> > > >
> > > > Thanks for any suggestions!
> > > >
> > > > Julie
 >> Stay informed about: Can I use ../@mp:localname? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
xml to SQL DB - We have some large existing Xml files that we'd like to store in the SQL server. We don't want to store just the Xml stream, but we rather like to build the hierarchical structure that represents the Xml in SQL and store the Xml that way. We also want...

how to store a word document in sql server - I Need help on how to store a word document in sql server.what datatype and how to convert it to store it. Pleas Help Thank you

SQLXML Prerequisites - I see that SQLXML 3.0 SP3 no longer depends on SOAP Toolkit 2.0 SP2. I have seen postings from earlier last year, i.e. Feb '04 (give or take a few months), that the prerequisite for SQL Server Client Tools would be removed. I don't see any mention o...

specify criteria dynamically with OpenXML - Hi Folks I need to put the following OPENXML into a while loop (to process each row individually), but don't seem to be able to apply a filter using variables. Don't seem to be able to find the docs/syntax to use variables here: [@StepName=''Process....

Q: mapping a single XML file into multiples SQL tables - Hello, I'm new to SQLXML features, and I'd wish to import xml files into SQL tables. Inspired from samples, I managed to do it for simple xml file like this, using a schema (at least I think this can be called a schema) XML file: <?xml version=&...
   Database Help (Home) -> XML All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]