You are viewing limited content. For full access, please sign in.

Question

Question

XMLPath language with Namespaces

asked on March 24, 2022 Show version history

I am running into an issue where by studying XMLPath on W3 Schools it is not teaching me to construct my queries correctly for XML files which contain namespaces.

So I learned to write my query like this, which works correctly on XML testers

/ExportedObjects/ExportedObject[ObjectValue/@superClasses="Document"]

Auto detection of name spaces doesn't make this suddenly work. So for a namespaced xml file I understand you must do this

 

Each element must be surrounded with:

/*[name()='element']

That results in this query

/*[name()='ExportedObjects']/*[name()='ExportedObject']/[*[name()='ObjectValue']/@superClasses="Document"]

But this query returns nothing as well, why is that?

I really wish I could just turn off namespaces since I don't see why I need them, I just want to browse the XML hierarchy since pattern matching is useless in hierarchical system

 

Update:

 

Based on this article I tried using /ExportedObjects:ExportedObjects instead and Workflow says that this is an invalid XPath expression

https://docs.microsoft.com/en-us/dotnet/standard/data/xml/xpath-queries-and-namespaces

0 0

Replies

replied on March 29, 2022

Please post an example XML file.  

1 0
replied on March 29, 2022

I am actively trying to get one without sensitive data in it. Will post when I get it.

0 0
replied on April 5, 2022

Uploading a sample XML file.

I want to get all ExportedObject where child ObjectValue has an attribute superClasses of Document

From W3 schools that query would be written like this

/ExportedObjects/ExportedObject[ObjectValue/@superClasses="Document"]

I have also tried replacing every element with the following syntax with no luck

/*[name()='element']

0 0
replied on April 5, 2022 Show version history

There was some weird line breaks in the sample file making it think that were a few unclosed tags.  Once I got that straightened out, it wasn't too bad.

This will give you all the nodes for superClasses="Document":

//ObjectValue[@superClasses='Document']

You don't need to have a full tree path, and that W3 syntax looks whack!

Then, just as an example, if you wanted the value of the LastModifier within that node:

//ObjectValue[@superClasses='Document']/Property[@propertyId="LastModifier"]/Value/text()

 

In the test file, there was only one node that had @superClasses='Document'?

You can validate this at http://xpather.com/

You don't really have to worry about namespaces unless nodes are prefixed.  As in:

<employee></employee>  vs. <i:employee></i:employee>

 

Hope this helps!

2 0
replied on April 6, 2022

The website you provided Xpather.com works with the queries your providing, which is interesting, however ultimately I need to do this using Laserfiche's XPath engine which does not accept these queries

See screenshot

Also, the other XPath engines I have been testing with online, do not accept these queries. Try this one for example: https://codebeautify.org/Xpath-Tester

Why is xpather.com able to get results and no one else can, including Laserfiche?

0 0
replied on April 6, 2022

The query you are entering is only selecting a node.  With this activity, you want to select a value.  What value do you want in that token?

0 0
replied on April 6, 2022 Show version history

I am trying to get the full path and metadata for each file. This is not all contained in values of elements, some of the data I need is contained in attributes such as the path and ID which references another node that contains the metadata.

This example only has 1 document with a full path of: 
/ADM Documents/Technology Services Documents/MOU/testdocument.pdf

So for each ObjectValue where one of it's elements named Property has an attribute classID="Document" I need:

  • It's attribute objectID's value (let's call this masterID)
  • It's parent elements child Property with an attribute called path's path attribute value
  • It's parent elements child Property where attribute propertyID="ContainmentName"
  • The Value of another ObjectValue with an attribute objectID=masterID's Property element with attribute propertyID="First_Name", etc for each field

 

Last time I had to do this was with an XML file that came from something called CD Plus and I used these types of queries without any issue.

/CDPlusDataSet/DistributionJobIndexes/DocumentID[text()='%(ReadXML_DocumentID)']/ancestor::DistributionJobIndexes/IndexValue

0 0
replied on April 6, 2022

This will get a few of the values from the two different nodes you were describing, but honestly, I don't know how it will react with more than one hit, and I would prefer to use an SDK script to give me more control:

//ObjectValue[@superClasses='Document']//Property[@propertyId='ContentType' or @propertyId='RetrievalName' or @propertyId='Creator']/Value/text() | //Value[@objectId=//ObjectValue[@superClasses='Document']/@objectId]/../../Property[@propertyId='Creator' or @propertyId='DateCreated']/Value/text()

0 0
replied on April 7, 2022

It doesn't work again in Workflow, where I need it to work. There are simply too many XPath engines all with their different outputs. I thought XPath was defined to create a standard for reading XML files.

0 0
replied on April 7, 2022

Why can't I even just get the most basic thing, the object ID from the object values?

//ObjectValue/@objectID

Every single thing I read on W3 or Stack Overflow, does not work. This is like an XML file from another planet.

replied on April 7, 2022 Show version history

Even just this most basic request, does not work.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.